question

max avatar image
max asked

C++ / Cocos2d-x Client SDK - Too much memory allocated in HTTPRequester

There's a small bug in the HTTPReequester C++ client code, allocating too much memory. I marked the line below with the fix.

std::stringHttpRequesterCURL::getDataFromResponse(cocos2d::network::HttpResponse* pResponse)
{
std::string sRetValue;
size_t tSize = pResponse->getResponseData()->size();
char* pData = reinterpret_cast<char*>(malloc(sizeof(char*) * (tSize + 1))); // <---- Should be sizeof(char)
if (tSize)
memcpy(pData, &(*pResponse->getResponseData())[0], tSize);
pData[tSize] = 0;
sRetValue = pData;
free(pData);
return sRetValue;
}
sdks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Thanks, Max - can you submit this as a pull request on the SDK?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.