valgrind

Simon Josefsson simon at josefsson.org
Fri Mar 2 14:40:20 CET 2012


Nikos Mavrogiannopoulos <nmav at gnutls.org> writes:

> On Wed, Feb 29, 2012 at 9:38 AM, Simon Josefsson <simon at josefsson.org> wrote:
>
>>> Hello,
>>>  It seems that in your system a pkcs11 module is causing a memory leak
>>> which prevents the test from succeeding. A work-around would be to
>>> run the test by temporarily disabling all pkcs11 modules loaded by p11-kit
>>> by removing /etc/pkcs11/modules. In the next release I'll remove the
>>> memory leak check completely to avoid such issues.
>> It seems clear that running valgrind on all self checks is causing a lot
>> of problems, but there are some checks we know should never have memory
>> leaks and running valgrind on them would be good.
>> One solution is to put these checks in a separate directory, and to only
>> enable valgrind in that directory.
>
> We currently use that (see directory slow), but still we have occasional
> unexpected failures in the rest. The current solution is to run valgrind
> in the development environment and do not run it on the system to
> be installed.
>
>> Another solution is to use a wrapper script instead of invoking valgrind
>> directly, and the wrapper script can have a whitelist of executables to
>> run under valgrind, and the rest will run without valgrind.
>
> The problem is that we have occasional failures that are system dependent
> and cannot be predicted, thus such a solution wouldn't add much. I think
> the enabling of valgrind in the development environment is the cleanest
> solution.

Yes, I agree.  I thought there were some self checks that had memory
leaks that we haven't fixed though, so there would still be two classes:
1) one set of checks with no memory leaks, where we run 'valgrind
--error-exitcode=1 --leak-check=full' on, and 2) one set of checks with
some known memory leak (potentially due to external libraries) where we
want to run valgrind with '--error=exitcode --leak-check=no' on.

There are some self-checks that leads to valgrind complaints now, for
example 'mini-loss-time' which produces the output below.  Why doesn't
valgrind exit with error code 1 for it?  Maybe it isn't possible to get
valgrind to exit with 1 on just memory leaks.

The current situation is quite OK, but it is easy for the valgrind
output to scroll by and we'd miss it.  It would be perfect if 'make
check' halted if there is a memory leak in a program, but that may
require a two-class approach initially to deal with checks that nobody
has fixed all the memory leaks for.

/Simon

==31600== 24 bytes in 1 blocks are still reachable in loss record 1 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x4E5C955: gnutls_credentials_set (gnutls_auth.c:105)
==31600==    by 0x4017B7: doit (mini-loss-time.c:150)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 40 bytes in 1 blocks are still reachable in loss record 2 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x4E67B4A: gnutls_system_mutex_init (system.c:201)
==31600==    by 0x4EE53C0: wrap_nettle_rnd_init (rnd.c:414)
==31600==    by 0x4E6E61B: _gnutls_rnd_init (random.c:37)
==31600==    by 0x4E61E27: gnutls_global_init (gnutls_global.c:251)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 40 bytes in 1 blocks are still reachable in loss record 3 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x4E67B4A: gnutls_system_mutex_init (system.c:201)
==31600==    by 0x4E61EBF: gnutls_global_init (gnutls_global.c:266)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 62 bytes in 3 blocks are still reachable in loss record 4 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x511D4D2: _asn1_set_value (parser_aux.c:222)
==31600==    by 0x511F577: asn1_array2tree (structure.c:199)
==31600==    by 0x4E61E1C: gnutls_global_init (gnutls_global.c:242)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 184 bytes in 1 blocks are still reachable in loss record 5 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x4EBA4B2: _gnutls_sr_send_params (safe_renegotiation.c:390)
==31600==    by 0x4E5C3F5: _gnutls_gen_extensions (gnutls_extensions.c:266)
==31600==    by 0x4E53682: _gnutls_send_hello (gnutls_handshake.c:1916)
==31600==    by 0x4E5406C: _gnutls_handshake_client (gnutls_handshake.c:2455)
==31600==    by 0x4E546FF: gnutls_handshake (gnutls_handshake.c:2368)
==31600==    by 0x4017F7: doit (mini-loss-time.c:162)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 312 bytes in 1 blocks are still reachable in loss record 6 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x4E6A40F: gnutls_init (gnutls_state.c:335)
==31600==    by 0x40177E: doit (mini-loss-time.c:142)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 504 bytes in 1 blocks are still reachable in loss record 7 of 17
==31600==    at 0x4C245E2: realloc (vg_replace_malloc.c:525)
==31600==    by 0x4E5C1ED: _gnutls_ext_register (gnutls_extensions.c:364)
==31600==    by 0x4E61E36: gnutls_global_init (gnutls_global.c:259)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 587 bytes in 60 blocks are still reachable in loss record 8 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x607FA21: strdup (strdup.c:43)
==31600==    by 0x511D42F: _asn1_set_name (parser_aux.c:364)
==31600==    by 0x511F551: asn1_array2tree (structure.c:197)
==31600==    by 0x4E61E1C: gnutls_global_init (gnutls_global.c:242)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 1,000 bytes in 1 blocks are still reachable in loss record 9 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x4E63673: _gnutls_epoch_alloc (gnutls_constate.c:741)
==31600==    by 0x4E6A322: gnutls_init (gnutls_state.c:308)
==31600==    by 0x40177E: doit (mini-loss-time.c:142)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 1,000 bytes in 1 blocks are still reachable in loss record 10 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x4E63673: _gnutls_epoch_alloc (gnutls_constate.c:741)
==31600==    by 0x4E547FD: gnutls_handshake (gnutls_handshake.c:2358)
==31600==    by 0x4017F7: doit (mini-loss-time.c:162)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 1,603 bytes in 73 blocks are still reachable in loss record 11 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x511D4D2: _asn1_set_value (parser_aux.c:222)
==31600==    by 0x511F577: asn1_array2tree (structure.c:199)
==31600==    by 0x4E61DF2: gnutls_global_init (gnutls_global.c:235)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 2,048 bytes in 1 blocks are still reachable in loss record 12 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x4C24562: realloc (vg_replace_malloc.c:525)
==31600==    by 0x4E6893A: _gnutls_buffer_append_data (gnutls_str.c:152)
==31600==    by 0x4E50522: _gnutls_send_handshake (gnutls_handshake.c:1234)
==31600==    by 0x4E536C2: _gnutls_send_hello (gnutls_handshake.c:1936)
==31600==    by 0x4E5406C: _gnutls_handshake_client (gnutls_handshake.c:2455)
==31600==    by 0x4E546FF: gnutls_handshake (gnutls_handshake.c:2368)
==31600==    by 0x4017F7: doit (mini-loss-time.c:162)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 4,312 bytes in 1 blocks are still reachable in loss record 13 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x4E6A307: gnutls_init (gnutls_state.c:304)
==31600==    by 0x40177E: doit (mini-loss-time.c:142)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 4,608 bytes in 64 blocks are still reachable in loss record 14 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x511E0EE: _asn1_add_node (parser_aux.c:61)
==31600==    by 0x511F53D: asn1_array2tree (structure.c:195)
==31600==    by 0x4E61E1C: gnutls_global_init (gnutls_global.c:242)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 5,223 bytes in 403 blocks are still reachable in loss record 15 of 17
==31600==    at 0x4C244E8: malloc (vg_replace_malloc.c:236)
==31600==    by 0x607FA21: strdup (strdup.c:43)
==31600==    by 0x511D42F: _asn1_set_name (parser_aux.c:364)
==31600==    by 0x511F551: asn1_array2tree (structure.c:197)
==31600==    by 0x4E61DF2: gnutls_global_init (gnutls_global.c:235)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 16,464 bytes in 1 blocks are definitely lost in loss record 16 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x4E4CD9A: _mbuffer_alloc (gnutls_mbuffers.c:287)
==31600==    by 0x4E4EC61: _gnutls_io_read_buffered (gnutls_buffers.c:171)
==31600==    by 0x4E49205: _gnutls_recv_in_buffers (gnutls_record.c:866)
==31600==    by 0x4E4E482: _gnutls_handshake_io_recv_int (gnutls_buffers.c:1173)
==31600==    by 0x4E51D0C: _gnutls_recv_handshake (gnutls_handshake.c:1260)
==31600==    by 0x4E558DE: _gnutls_recv_server_kx_message (gnutls_kx.c:470)
==31600==    by 0x4E543CF: _gnutls_handshake_client (gnutls_handshake.c:2502)
==31600==    by 0x4E546FF: gnutls_handshake (gnutls_handshake.c:2368)
==31600==    by 0x4017F7: doit (mini-loss-time.c:162)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31600== 36,576 bytes in 508 blocks are still reachable in loss record 17 of 17
==31600==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31600==    by 0x511E0EE: _asn1_add_node (parser_aux.c:61)
==31600==    by 0x511F53D: asn1_array2tree (structure.c:195)
==31600==    by 0x4E61DF2: gnutls_global_init (gnutls_global.c:235)
==31600==    by 0x40175A: doit (mini-loss-time.c:130)
==31600==    by 0x4019AC: main (utils.c:155)
==31600== 
==31597== 16 bytes in 1 blocks are still reachable in loss record 1 of 1
==31597==    at 0x4C2380C: calloc (vg_replace_malloc.c:467)
==31597==    by 0x4E63A96: gnutls_anon_allocate_server_credentials (gnutls_anon_cred.c:62)
==31597==    by 0x401637: doit (mini-loss-time.c:222)
==31597==    by 0x4019AC: main (utils.c:155)
==31597== 
PASS: mini-loss-time




More information about the Gnutls-devel mailing list