Closed musicinmybrain closed 3 years ago
According to documenation it is false positive:
This function is intended to be useful when using memory-checking tools such as valgrind. When valgrind's memcheck analyzes a cairo-using program without a call to cairo_debug_reset_static_data(), it will report all data reachable via cairo's static objects as "still reachable". Calling cairo_debug_reset_static_data() just prior to program termination will make it easier to get squeaky clean reports from valgrind.
This function is intended to be useful when using memory-checking tools such as valgrind. When valgrind's memcheck analyzes a cairo-using program without a call to cairo_debug_reset_static_data(), it will report all data reachable via cairo's static objects as "still reachable". Calling cairo_debug_reset_static_data() just prior to program termination will make it easier to get squeaky clean reports from valgrind
I think we can safely add it to the end of main().
The interesting thing is that the documentation talks only about “still reachable” memory, which, sure, Valgrind saw plenty of that, and by default doesn’t complain about it—but the Valgrind/memcheck
report is about “definitely lost” and “indirectly lost” memory. It’s possible that adding cairo_debug_reset_static_data()
somehow accidentally papers over a real problem rather than just suppressing a false positive.
On the other hand, I’m not convinced the leak is a sndfile-tools
problem, and in any case a small-ish memory leak in a one-shot command-line tool is the least concerning kind of memory error compared to other things Valgrind is able to find, like relying on uninitialized memory or overrunning a buffer.
How do you think, it is better to add cairo_debug_reset_static_data()
?
I wasn’t sure. I’m still not 100% sure, but after further examination, I think that the “leaked” memory is indeed indirectly held by one of cairo’s static objects, and Valgrind can’t see the reference to it because fontconfig
uses an integer offset instead of a pointer in FcPattern
to reference the associated “elements.”
If I’m right about that, then it is actually a false positive from Valgrind, and adding cairo_debug_reset_static_data()
to avoid it is the right thing to do.
So, pull request? :smile:
Ok, sure, I’ll “commit to” this solution. :stuck_out_tongue:
When I run the tests on Fedora 34 x86_64, after applying https://github.com/libsndfile/sndfile-tools/pull/74 and https://github.com/libsndfile/sndfile-tools/pull/75, I still get a leak in
sndfile-spectrogram
.I’m not using any special build flags. (
./autogen.sh && ./configure && make -j
)A quick review of
spectrogram.c
didn’t reveal any obvious problems, nor did a quick skim through the relevant cairo internals.Adding
cairo_debug_reset_static_data()
at the end of the main routine does “fix” the leak, although I am not suggesting it as a patch.I’m reporting this in case someone else readily spots what I missed.