regarding thread safe problem, any idea is welcome.

Hi,guys:
recently I found my game always crashes on Galaxy S4 in uncertain scenes(not everytime),I have found this problem before on Galaxy S2, but when I use a schedule to catch the status of HttpClient download, it does not happen frequently(but still happens), because my game is based on web server, so most of game actions will connect to web server, but now I think I am annoying from thread safe problem, can anybody help,please.
(my game always crashes in uncertain scenes)

  1. first,I download data from web server using this function and a callback function as below, and also, I register a schedule function and trigger it every 0.3 seconds:
    void WuXiaButtonSaleBuy::buyCard() { status = BuyCardButtonBuying; this->schedule(schedule_selector(WuXiaButtonSaleBuy::CheckStatus),0.3f); cocos2d::extension::CCHttpRequest* request = new cocos2d::extension::CCHttpRequest(); char* url= new char[1024]; string buySaleParams = WuXiaPlayer::player->sessionId.c_str(); buySaleParams.append("," + saleId); sprintf(url,"%sbuyCard.aspx?text=%s",WuXiaServer::SecondaryServer,base64_encode(buySaleParams.c_str()).c_str()); request->setUrl(url); request->setRequestType(cocos2d::extension::CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(WuXiaButtonSaleBuy::OnBuyCompleted)); cocos2d::extension::CCHttpClient::getInstance()->send(request); request->release(); delete url; }

  2. when game data downloaded from server, I save data to butResult and change status to Bought.
    `void WuXiaButtonSaleBuy::OnBuyCompleted(cocos2d::extension::CCHttpClient* client, cocos2d::extension::CCHttpResponse* response)
    {
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    std::vector buffer = response->getResponseData();
    char
    cString = new char[buffer->size()];
    for (unsigned int i=0;isize();i++)
    {
    sprintf(cString+i,"%c",(*buffer)[i]);
    }

    std::string newStr(cString);

    std::size_t found = newStr.find(“ERROR”);
    if (found==std::string::npos && newStr.find(“SUCCESS#” ) != std::string::npos && newStr.find("#SUCCESS" ) != std::string::npos)
    {
    buyResult = newStr;
    status = BuyCardButtonBought;
    }
    else
    {
    status = BuyCardButtonFailed;
    }
    }`

  3. finally, my schedule function will check the status of downloading, and do something for the status like the following:
    `void WuXiaButtonSaleBuy::CheckStatus(float dtTime)
    {
    if (status == BuyCardButtonFailed)
    {
    // ask player whether to buy again or not.
    return;
    }

    if (status == BuyCardButtonBought)
    {
    // do something when successfully bought a card.
    status = BuyCardButtonNormal;
    }
    }`

somebody help please.

solved!
I changed “char cString = new char[buffer->size()];” to
“char cString = new char[buffer->size()+1];”

no crashes.