-
Notifications
You must be signed in to change notification settings - Fork 633
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
Latent memory leak in pngtest #496
Comments
No a bug in libpng. This is a test program that only gets run while building libpng so memory leaks are irrelevant as, indeed, are any problems since pngtest is only run with very specific images (and immediately exits on error, causing the build to fail!) |
This is not a concern for running the test, but |
@vesalvojdani I take your point about it being a bad example but your suggested change does not seem to fix anything. This is covered by section 4.6.2.1 lines 11-14 of ANSI X3.159-1989 (identical to ISO C90, but I don't have a copy of that, see the end of this comment). @ctruta: the problem seems to have been introduced by the referenced PR. This is because
So it really is an example; a bad example! I suggest replacing it in the manual with To fix the bug introduced by the previous (2019) change simply put @vesalvojdani you are indeed correct that taking the address of something often fixes the problem, but not in this case; at the point Note that
Note that Note that the ANSI-C standard is not widely available and supposed copies on the web may be bogus (I found one such copy). This seems to be correct: https://www.bsb.me.uk/ansi-c/ansi-c#sec_4_6_2 To be sure I'll copy and paste the paragraph with added emphasis (i.e. I put the bold and italic bits in):
|
Try this: https://github.com/jbowler/libpng/tree/pr496 It passes make check, make distcheck, cmake and contib/examples all compile without warnings (-Wall -Wextra to gcc). I have gcc 13.2.1 |
@ctruta: [libpng18] Easy solution, remove pngtest :-) |
A memory leak in pngtest (#265) was fixed (8439534) by freeing row buffer when libpng exits via longjmp. There is still the risk that
row_buf
is clobbered when jumping back. This is unlikely in the current implementation since reading and writing expose the address of the pointer to the library functions. But the manual also suggests that single lines can be read as follows:The above change seems innocent, but the memory leak reported in #265 can now be reproduced. Using the same file, I can see leaks with ASAN (
export CC=/usr/bin/clang CFLAGS="-g -O2 -fsanitize=address"
; note the-O2
here). I also see clobbering by adding debug statements before free and compiling with the default configure/make on an Ubuntu machine.Since the
pngtest.c
file is referenced in the manual and serves as an example, consider makingrow_buf
volatile or static, so that one does not run into this kind of a memory leak when making reasonable alterations to the example program.The text was updated successfully, but these errors were encountered: