Re: memory leaks in FXFont::listFonts()
[email protected] Mon, 08 Jan 2024 08:37:51 -0600
| Newsgroups | gmane.comp.lib.fox-toolkit.user |
|---|---|
| Message-ID | <[email protected]> |
On 2024-01-06 16:49, John Selverian wrote:
> I ran my program on Linux with these complier options
>
>
>
> -fsanitize=address -ggdb3
>
>
>
> And I get these leaks, I think they are all in
> FX::FXFont::listFonts()
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> =================================================================
>
> ==29369==ERROR: LeakSanitizer: detected memory leaks
>
>
>
> Direct leak of 111736 byte(s) in 1 object(s) allocated from:
>
> #0 0x7f8dc6c79808 in __interceptor_malloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
>
> #1 0x7f8dc6a0dc74 in XftFontOpenInfo
> (/usr/lib/x86_64-linux-gnu/libXft.so.2+0xcc74)
>
>
>
> Direct leak of 18304 byte(s) in 1 object(s) allocated from:
>
> #0 0x7f8dc6c79c3e in __interceptor_realloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
>
> #1 0x55a8988204c5 in FX::fxresize(void**, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa6e4c5)
>
> #2 0x55a8987d6b80 in bool
> FX::resizeElms<FX::FXFontDesc>(FX::FXFontDesc*&, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa24b80)
>
> #3 0x55a8987d53b5 in FX::FXFont::listFonts(FX::FXFontDesc*&,
> unsigned int&, FX::FXString const&, unsigned int, unsigned int,
> unsigned int, unsigned int, unsigned int)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa233b5)
>
> #4 0x55a88b03971e in Mpdb::setDefaultFont()
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:9636
>
> #5 0x55a88b03af3e in Mpdb::assignProgramDefaults()
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:9572
>
>
>
> Direct leak of 18304 byte(s) in 1 object(s) allocated from:
>
> #0 0x7f8dc6c79c3e in __interceptor_realloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
>
> #1 0x55a8988204c5 in FX::fxresize(void**, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa6e4c5)
>
> #2 0x55a8987d6b80 in bool
> FX::resizeElms<FX::FXFontDesc>(FX::FXFontDesc*&, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa24b80)
>
> #3 0x55a8987d53b5 in FX::FXFont::listFonts(FX::FXFontDesc*&,
> unsigned int&, FX::FXString const&, unsigned int, unsigned int,
> unsigned int, unsigned int, unsigned int)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa233b5)
>
> #4 0x55a88b03971e in Mpdb::setDefaultFont()
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:9636
>
> #5 0x55a88b0651ce in Mpdb::Mpdb(FX::FXApp*)
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:509
>
> #6 0x55a88b09d44f in main /home/jhs1/mpdb/MPDB/Mpdb.cpp:16878
>
> #7 0x7f8dc6027082 in __libc_start_main
> ../csu/libc-start.c:308
>
>
>
> Direct leak of 3712 byte(s) in 1 object(s) allocated from:
>
> #0 0x7f8dc6c79c3e in __interceptor_realloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
>
> #1 0x55a8988204c5 in FX::fxresize(void**, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa6e4c5)
>
> #2 0x55a8987d6b80 in bool
> FX::resizeElms<FX::FXFontDesc>(FX::FXFontDesc*&, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa24b80)
>
> #3 0x55a8987d53b5 in FX::FXFont::listFonts(FX::FXFontDesc*&,
> unsigned int&, FX::FXString const&, unsigned int, unsigned int,
> unsigned int, unsigned int, unsigned int)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa233b5)
>
> #4 0x55a88b03941f in Mpdb::setDefaultFont()
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:9606
>
> #5 0x55a88b0651ce in Mpdb::Mpdb(FX::FXApp*)
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:509
>
> #6 0x55a88b09d44f in main /home/jhs1/mpdb/MPDB/Mpdb.cpp:16878
>
> #7 0x7f8dc6027082 in __libc_start_main
> ../csu/libc-start.c:308
>
>
>
> Direct leak of 3712 byte(s) in 1 object(s) allocated from:
>
> #0 0x7f8dc6c79c3e in __interceptor_realloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
>
> #1 0x55a8988204c5 in FX::fxresize(void**, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa6e4c5)
>
> #2 0x55a8987d6b80 in bool
> FX::resizeElms<FX::FXFontDesc>(FX::FXFontDesc*&, unsigned long)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa24b80)
>
> #3 0x55a8987d53b5 in FX::FXFont::listFonts(FX::FXFontDesc*&,
> unsigned int&, FX::FXString const&, unsigned int, unsigned int,
> unsigned int, unsigned int, unsigned int)
> (/home/jhs1/mpdb/MPDB/MPDB_linux+0xfa233b5)
>
> #4 0x55a88b03941f in Mpdb::setDefaultFont()
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:9606
>
> #5 0x55a88b03af3e in Mpdb::assignProgramDefaults()
> /home/jhs1/mpdb/MPDB/Mpdb.cpp:9572
>
>
>
> Direct leak of 1536 byte(s) in 2 object(s) allocated from:
>
> #0 0x7f8dc6c79c3e in __interceptor_realloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
>
> #1 0x7f8dc69ce3a0
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x213a0)
>
>
>
> Direct leak of 256 byte(s) in 1 object(s) allocated from:
>
> #0 0x7f8dc6c79808 in __interceptor_malloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
>
> #1 0x7f8dc69ce2f4
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x212f4)
>
>
>
> Indirect leak of 111736 byte(s) in 1 object(s) allocated from:
>
> #0 0x7f8dc6c79808 in __interceptor_malloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
>
> #1 0x7f8dc6a0dc74 in XftFontOpenInfo
> (/usr/lib/x86_64-linux-gnu/libXft.so.2+0xcc74)
>
>
>
> Indirect leak of 1408 byte(s) in 44 object(s) allocated from:
>
> #0 0x7f8dc6c79a06 in __interceptor_calloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
>
> #1 0x7f8dc69cde0f
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x20e0f)
>
>
>
> Indirect leak of 1376 byte(s) in 43 object(s) allocated from:
>
> #0 0x7f8dc6c79808 in __interceptor_malloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
>
> #1 0x7f8dc6a1010d in XftFontCheckGlyph
> (/usr/lib/x86_64-linux-gnu/libXft.so.2+0xf10d)
>
>
>
> Indirect leak of 840 byte(s) in 26 object(s) allocated from:
>
> #0 0x7f8dc6c023ed in __interceptor_strdup
> ../../../../src/libsanitizer/asan/asan_interceptors.cc:445
>
> #1 0x7f8dc69cdb64 in FcValueSave
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x20b64)
>
>
>
> Indirect leak of 608 byte(s) in 19 object(s) allocated from:
>
> #0 0x7f8dc6c79a06 in __interceptor_calloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
>
> #1 0x7f8dc69ce93c
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x2193c)
>
>
>
> Indirect leak of 384 byte(s) in 12 object(s) allocated from:
>
> #0 0x7f8dc6c79a06 in __interceptor_calloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
>
> #1 0x7f8dc69cdcae
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x20cae)
>
>
>
> Indirect leak of 128 byte(s) in 4 object(s) allocated from:
>
> #0 0x7f8dc6c79a06 in __interceptor_calloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
>
> #1 0x7f8dc69cddb4
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x20db4)
>
>
>
> Indirect leak of 96 byte(s) in 2 object(s) allocated from:
>
> #0 0x7f8dc6c79808 in __interceptor_malloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
>
> #1 0x7f8dc69c7e11 in FcLangSetCreate
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1ae11)
>
>
>
> Indirect leak of 48 byte(s) in 2 object(s) allocated from:
>
> #0 0x7f8dc6c79808 in __interceptor_malloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
>
> #1 0x7f8dc69cd931 in FcPatternCreate
> (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x20931)
>
>
>
> SUMMARY: AddressSanitizer: 274184 byte(s) leaked in 161
> allocation(s).
==========
I'm aware of leaks in fontconfig/Xft libraries. I'm typically using
valgrind
for this stuff:
valgrind --malloc-fill=0xff --show-reachable=yes --leak-check=yes
<yourprogram> >& leaks.txt
Did this fox adie, I'm getting (I'll list the summary only), after
changing fonts *once* using the font selector:
==33478== LEAK SUMMARY:
==33478== definitely lost: 7,680 bytes in 28 blocks
==33478== indirectly lost: 3,940 bytes in 167 blocks
==33478== possibly lost: 36,536 bytes in 86 blocks
==33478== still reachable: 372,001 bytes in 8,804 blocks
==33478== suppressed: 0 bytes in 0 blocks
When just starting, loading a file, and recording the results with
valgrind
I'm getting this:
==33953== LEAK SUMMARY:
==33953== definitely lost: 7,680 bytes in 28 blocks
==33953== indirectly lost: 3,940 bytes in 167 blocks
==33953== possibly lost: 36,776 bytes in 92 blocks
==33953== still reachable: 371,821 bytes in 8,804 blocks
==33953== suppressed: 0 bytes in 0 blocks
The difference here is in the "possibly lost" and "still reachable"
categories.
The question is what memory leaks are in the "acceptable" or
"explainable"
category.
I'd say, these would be:
1) Per-thread dynamically allocated data to make some functions
thread-safe.
Since its the main thread we're talking about, any allocations for
the
purpose of thread-local variables will necessarily stay around until
the
main thread dies.
2) Annoying but unlikely to cause trouble: allocations which are leaked
but
which do not grow over time, e.g. repeatedly listing fonts etc.
Curiously in the example above, the first case I listed and then
switched
fonts, while in the second case I did not; yet the first case
actually
ends up with less memory in the possibly lost category.
3) Memory in the "still reachable" category may have some legitimate
reason
to remain allocated. Perhaps someone is caching something behind the
scenes?
Ideally I'd like all dynamic allocations to end up at 0 after the run,
no
question. But sometimes there may be allocations which are explainable
that serve a legimate purpose, such as the ones mentioned above.
Of course, there are possibly leaks in libraries that are used from FOX,
and as much as FOX tries to release all of *its* allocations, we're
simply
unable to do anything about stuff allocated in libraries that we're
using.
That said, I think we're probably OK.
-- JVZ