tracking down (potential) memory leaks in arb with clang and AddressSanitizer

155 views
Skip to first unread message

Stephen Crowley

unread,
May 28, 2022, 5:09:12 PM5/28/22
to flint-devel
I'm trying to track down memory leaks to see if they are coming from arb internally or are specific to the way I've made arb4j use arb


Has anyone done any extensive testing on arb for memory leaks? I've encountered a slow but persistent leak in arb4j and ruled out JVM stuff like garbage collection or java leaks.. I'll try to fix any bugs I find before reporting but just wanted to ask about anything done in this area first

--Stephen

Fredrik Johansson

unread,
May 28, 2022, 5:24:00 PM5/28/22
to flint-devel
I do test extensively for memory leaks using valgrind. There shouldn't be any leaks in any core functions but I can't guarantee that there aren't leaks anywhere in the library.

By memory leak I assume you mean that memory grows linearly with time. It is normal that Arb/Flint allocate some persistent caches which don't get freed automatically, but which can be freed manually with flint_cleanup() / flint_cleanup_master().

Fredrik

--

---
You received this message because you are subscribed to the Google Groups "flint-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flint-devel...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/flint-devel/e0d1ed91-a467-4791-bea4-7ea7493c2c85n%40googlegroups.com.

Stephen Crowley

unread,
May 28, 2022, 8:47:50 PM5/28/22
to flint-devel
Thanks! I think its a bug in my code somewhere but I wont be sure until I can get the stacktrace deeper than flint_malloc

screen=java.awt.Dimension[width=500,height=250]
domain=java.awt.geom.Rectangle2D$Double[x=-3.141592653589793,y=-1.5,w=6.283185307179586,h=3.0]
Rendered in 0.634 seconds at a rate of 197161 pixels/sec

=================================================================
==495650==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64841208 byte(s) in 2026116 object(s) allocated from:
    #0 0x7f59a7bfd867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f532801353d in flint_malloc memory_manager.c:91

Direct leak of 341568 byte(s) in 10674 object(s) allocated from:
    #0 0x7f59a7bfdc18 in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x7f5328015bb2 in flint_realloc memory_manager.c:118

Indirect leak of 2560 byte(s) in 80 object(s) allocated from:
    #0 0x7f59a7bfd867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f532801353d in flint_malloc memory_manager.c:91

-----------------------------------------------------
Suppressions used:
  count      bytes template
   3004     204212 libjvm.so
    185      30532 libX11.so
    115    2001368 libz.so.1
     16       3728 libawt_xawt.so
     69       7728 libzip.so
      2       3664 libXext.so.6
      2       5802 main
-----------------------------------------------------

SUMMARY: AddressSanitizer: 65185336 byte(s) leaked in 2036870 allocation(s).

Stephen Crowley

unread,
May 28, 2022, 11:53:58 PM5/28/22
to flint-devel
The problem was that I had overlooked the fact that the close() method was  calling delete() not clear() and so instead was just using the standard free method instead of the way it is supposed to be done.
Thanks for the quick reply, arb is awesome, thank you to you and all the other arb contributors,

Best regards,
Stephen


screen=java.awt.Dimension[width=500,height=250]
domain=java.awt.geom.Rectangle2D$Double[x=-3.141592653589793,y=-1.5,w=6.283185307179586,h=3.0]
Rendered in 0.633 seconds at a rate of 197472 pixels/sec

=================================================================
==880916==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7776 byte(s) in 41 object(s) allocated from:
    #0 0x7f4cb2841867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f4632e7353d in flint_malloc memory_manager.c:91

Indirect leak of 2432 byte(s) in 76 object(s) allocated from:
    #0 0x7f4cb2841867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f4632e7353d in flint_malloc memory_manager.c:91


-----------------------------------------------------
Suppressions used:
  count      bytes template
   3041     211156 libjvm.so
    184      30372 libX11.so
    112    1903064 libz.so.1
     15       3496 libawt_xawt.so

     69       7728 libzip.so
      2       3664 libXext.so.6
      2       5802 main
-----------------------------------------------------

SUMMARY: AddressSanitizer: 10208 byte(s) leaked in 117 allocation(s).
Reply all
Reply to author
Forward
0 new messages