Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in png2pnm #288

Open
tangyaofang opened this issue May 9, 2019 · 2 comments
Open

Memory Leak in png2pnm #288

tangyaofang opened this issue May 9, 2019 · 2 comments

Comments

@tangyaofang
Copy link
Contributor

tangyaofang commented May 9, 2019

issue: #239 unsolved. The same error in the new version 1.6.37:

root@KWE1000859128:/home/test/libpng-1.6.37/contrib/pngminus# ./png2pnm crash_png2pnm_memory_leak 1.pnm
libpng error: Read Error
PNG2PNM
Error: unsuccessful conversion of PNG-image

=================================================================
==100062==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 160 byte(s) in 1 object(s) allocated from:
#0 0x4b8da8 (/home/test/libpng-1.6.37/contrib/pngminus/png2pnm+0x4b8da8)
#1 0x4ebb16 (/home/test/libpng-1.6.37/contrib/pngminus/png2pnm+0x4ebb16)
#2 0x4eab4d (/home/test/libpng-1.6.37/contrib/pngminus/png2pnm+0x4eab4d)
#3 0x7f42e320582f (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 2400 byte(s) in 1 object(s) allocated from:
#0 0x4b8da8 (/home/test/libpng-1.6.37/contrib/pngminus/png2pnm+0x4b8da8)
#1 0x4eba76 (/home/test/libpng-1.6.37/contrib/pngminus/png2pnm+0x4eba76)
#2 0x4eab4d (/home/test/libpng-1.6.37/contrib/pngminus/png2pnm+0x4eab4d)
#3 0x7f42e320582f (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: 2560 byte(s) leaked in 2 allocation(s).

@tangyaofang
Copy link
Contributor Author

tangyaofang commented May 10, 2019

@ctruta :

The issue is:
In the contrib\pngminus\png2pnm.c file, when the png_read_image (png_ptr, row_pointers) statement fails, the previously requested png_pixels row_pointers memory is not released.
I think I have modified this problem and released the requested png_pixels row_pointers memory when an exception is caught.
The following is my modification, please confirm that my modification is correct:

if (setjmp (png_jmpbuf(png_ptr)))
  {
    png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
    if (row_pointers != NULL)
    {
      free (row_pointers);
      row_pointers = NULL;
    }      
    if (png_pixels != NULL)
    {
      free (png_pixels);
      png_pixels = NULL;
    }      
    return FALSE;
  }

@jbowler
Copy link
Contributor

jbowler commented Nov 16, 2022

There is no memory leak here, the program has exited with a fatal error (and this is the correct behavior).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants