Menu

#201 Memory leak in contrib/gregbook/readpng.c

libpng_code
closed-fixed
None
5
2013-04-04
2013-03-01
No

Memory leak in contrib/gregbook/readpng.c

In function readpng_get_image: if error happens at png_read_image(…) we go to setjmp(…) where png_ptr and info_ptr will be deleted, but image_data and row_pointers does not.

Possible fix: change what setjmp(…) to this:

if (setjmp(png_jmpbuf(png_ptr))) {
    png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
    free(image_data);
    free(row_pointers);
    return NULL;
}

Discussion

  • Glenn Randers-Pehrson

    • status: open --> open-accepted
     
  • Glenn Randers-Pehrson

    Thanks. It's probably safer this way:

    diff a/contrib/gregbook/readpng.c b/contrib/gregbook/readpng.c
    217a218,225

        if (image_data != NULL) {
           free(image_data);
           image_data = NULL;
        }
        if (row_pointers != NULL) {
           free(row_pointers);
           row_pointers = NULL;
        }
    
     
  • Glenn Randers-Pehrson

    It's been pointed out to me that it's not necessary to check for the NULL pointers; readpng.c guarantees that they are initialized to NULL.
    The patch has been applied to the libpngNN branches of the libpng GIT repository and will appear in the next releases.

     

    Last edit: Glenn Randers-Pehrson 2013-03-01
  • Glenn Randers-Pehrson

    Fixed in libpng-1.5.15 and libpng-1.6.1, thanks.

     
  • Glenn Randers-Pehrson

    • status: open-accepted --> closed-fixed
    • assigned_to: Glenn Randers-Pehrson
     

Log in to post a comment.

MongoDB Logo MongoDB