don't free() the same pointer twice if an error occurs during lines pointers allocation
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_9_0_BRANCH@60875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -558,18 +558,16 @@ wxPNGHandler::LoadFile(wxImage *image,
|
|||||||
if (!image->Ok())
|
if (!image->Ok())
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
lines = (unsigned char **)malloc( (size_t)(height * sizeof(unsigned char *)) );
|
// initialize all line pointers to NULL to ensure that they can be safely
|
||||||
|
// free()d if an error occurs before all of them could be allocated
|
||||||
|
lines = (unsigned char **)calloc(height, sizeof(unsigned char *));
|
||||||
if ( !lines )
|
if ( !lines )
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
for (i = 0; i < height; i++)
|
for (i = 0; i < height; i++)
|
||||||
{
|
{
|
||||||
if ((lines[i] = (unsigned char *)malloc( (size_t)(width * (sizeof(unsigned char) * 4)))) == NULL)
|
if ((lines[i] = (unsigned char *)malloc( (size_t)(width * (sizeof(unsigned char) * 4)))) == NULL)
|
||||||
{
|
|
||||||
for ( unsigned int n = 0; n < i; n++ )
|
|
||||||
free( lines[n] );
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
png_read_image( png_ptr, lines );
|
png_read_image( png_ptr, lines );
|
||||||
|
Reference in New Issue
Block a user