[erlang-questions] Tracking memory leaks in NIF/Linkedin drivers with Valgrind (or anything else)

Zabrane Mickael zabrane3@REDACTED
Sun Mar 17 10:35:33 CET 2013


Hi guys,

I'm trying to use Valgrind to track memory leaks in C NIF/Linkedin drivers.
For this, I've built a "Debug  Enabled" ERTS with Valgrind and SMP flavor:
http://www.erlang.org/doc/installation_guide/INSTALL.html

1/ First attempt: start an Erlang node and turn it off immediately:

$ cerl -valgrind
[...]

1> init:stop().

[...]
==61127==    at 0xC713: malloc (vg_replace_malloc.c:274)
==61127==    by 0x1002C25F0: erts_sys_alloc (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==61127==    by 0x10000B6B3: erts_alloc (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==61127==    by 0x10000B5AC: erts_alloc_permanent_cache_aligned (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==61127==    by 0x1001053E7: init_db (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==61127==    by 0x10002884B: erl_init (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==61127==    by 0x10002D273: erl_start (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==61127==    by 0x10000191F: main (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==61127== 
==61127== ERROR SUMMARY: 420 errors from 13 contexts (suppressed: 0 from 0)

420 errors reported.

Rickard Green explained why Valgrind reported these (false) numbers at:
http://erlang.org/pipermail/erlang-questions/2010-February/049591.html


2/ Second attempt: simply load "crypto" module and stop it:

$ cerl -valgrind
[...]

1> crypto:start().
2> crypto:stop(). 
ok
3> 
=INFO REPORT==== 17-Mar-2013::10:18:26 ===
    application: crypto
    exited: stopped
    type: temporar
4> init:stop().

[...]
==59400==    at 0xC713: malloc (vg_replace_malloc.c:274)
==59400==    by 0x1002C25F0: erts_sys_alloc (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==59400==    by 0x10000B6B3: erts_alloc (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==59400==    by 0x10000B5AC: erts_alloc_permanent_cache_aligned (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==59400==    by 0x1001053E7: init_db (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==59400==    by 0x10002884B: erl_init (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==59400==    by 0x10002D273: erl_start (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==59400==    by 0x10000191F: main (in /opt/r16b/usr/lib/erlang/erts-5.10.1/bin/beam.valgrind.smp)
==59400== 
==59400== ERROR SUMMARY: 460 errors from 15 contexts (suppressed: 0 from 0)

Valgrind now reorts 460 errors instead of 420 (see above).

I know, there's no memory leak in "crypto" ... but this doesn't help at all. Completely useless.

So, my question is very simple: 
How Valgrind can help me to track memory leaks in my own NIF/linked-in drivers then?
How can I distinguish between these falsy reported numbers and the real ones?

Finally, is there any other way than Valgrind?

Regards,
Zabrane



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130317/ccdbc21b/attachment.htm>


More information about the erlang-questions mailing list