Skip to content

Commit

Permalink
Merge pull request #6261 from iSevenDays/patch-9
Browse files Browse the repository at this point in the history
Fix memory leak
  • Loading branch information
minggo committed Apr 18, 2014
2 parents 428bac9 + df0f24f commit 3e0a0ec
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cocos/2d/platform/CCImage.cpp
Expand Up @@ -942,7 +942,14 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)

_dataLen = rowbytes * _height;
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
CC_BREAK_IF(!_data);
if(!_data)
{
if (row_pointers != nullptr)
{
free(row_pointers);
}
break;
}

for (unsigned short i = 0; i < _height; ++i)
{
Expand All @@ -957,7 +964,7 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
if (row_pointers != nullptr)
{
free(row_pointers);
};
}

bRet = true;
} while (0);
Expand Down Expand Up @@ -2028,6 +2035,9 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
{
fclose(fp);
png_destroy_write_struct(&png_ptr, &info_ptr);

free(row_pointers);
row_pointers = nullptr;
break;
}

Expand Down

0 comments on commit 3e0a0ec

Please sign in to comment.