bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

di-set: Fix memory leak


From: Bruno Haible
Subject: di-set: Fix memory leak
Date: Sun, 10 Mar 2019 14:20:09 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; )

Building a gnulib testdir with CC="gcc -fsanitize=leak", I see this finding
in 'test-di-set':

ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 1 object(s) allocated from:
    #0 0x7f874eea8858 in __interceptor_malloc 
../../../../gcc-8.2.0/libsanitizer/lsan/lsan_interceptors.cc:52
    #1 0x401aee in hash_initialize ../../gllib/hash.c:605

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f874eea8858 in __interceptor_malloc 
../../../../gcc-8.2.0/libsanitizer/lsan/lsan_interceptors.cc:52
    #1 0x40259e in ino_map_insert ../../gllib/ino-map.c:133

Indirect leak of 20432 byte(s) in 1 object(s) allocated from:
    #0 0x7f874eea9404 in __interceptor_calloc 
../../../../gcc-8.2.0/libsanitizer/lsan/lsan_interceptors.cc:74
    #1 0x401b59 in hash_initialize ../../gllib/hash.c:626

Indirect leak of 32 byte(s) in 2 object(s) allocated from:
    #0 0x7f874eea8858 in __interceptor_malloc 
../../../../gcc-8.2.0/libsanitizer/lsan/lsan_interceptors.cc:52
    #1 0x40259e in ino_map_insert ../../gllib/ino-map.c:133

SUMMARY: LeakSanitizer: 20560 byte(s) leaked in 5 allocation(s).
FAIL test-di-set (exit status: 23)


It is confirmed by valgrind:

$ valgrind --tool=memcheck --num-callers=20 --leak-check=yes 
--leak-resolution=high --show-reachable=yes ./test-di-set 
==5309== Memcheck, a memory error detector
==5309== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==5309== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==5309== Command: ./test-di-set
==5309== 
==5309== 
==5309== HEAP SUMMARY:
==5309==     in use at exit: 20,560 bytes in 5 blocks
==5309==   total heap usage: 27 allocs, 22 frees, 314,688 bytes allocated
==5309== 
==5309== 16 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==5309==    at 0x4C2DB8F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5309==    by 0x40202E: ino_map_insert (ino-map.c:133)
==5309==    by 0x400BDF: di_set_insert (di-set.c:231)
==5309==    by 0x40073A: main (test-di-set.c:39)
==5309== 
==5309== 16 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==5309==    at 0x4C2DB8F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5309==    by 0x40202E: ino_map_insert (ino-map.c:133)
==5309==    by 0x400BDF: di_set_insert (di-set.c:231)
==5309==    by 0x400757: main (test-di-set.c:40)
==5309== 
==5309== 16 bytes in 1 blocks are definitely lost in loss record 3 of 5
==5309==    at 0x4C2DB8F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5309==    by 0x40202E: ino_map_insert (ino-map.c:133)
==5309==    by 0x400BDF: di_set_insert (di-set.c:231)
==5309==    by 0x40079F: main (test-di-set.c:47)
==5309== 
==5309== 20,432 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==5309==    at 0x4C2FB55: calloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5309==    by 0x401563: hash_initialize (hash.c:626)
==5309==    by 0x401F96: ino_map_alloc (ino-map.c:90)
==5309==    by 0x400AEB: map_inode_number.isra.1 (di-set.c:208)
==5309==    by 0x400BDF: di_set_insert (di-set.c:231)
==5309==    by 0x40073A: main (test-di-set.c:39)
==5309== 
==5309== 20,544 (80 direct, 20,464 indirect) bytes in 1 blocks are definitely 
lost in loss record 5 of 5
==5309==    at 0x4C2DB8F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5309==    by 0x4014EE: hash_initialize (hash.c:605)
==5309==    by 0x401F96: ino_map_alloc (ino-map.c:90)
==5309==    by 0x400AEB: map_inode_number.isra.1 (di-set.c:208)
==5309==    by 0x400BDF: di_set_insert (di-set.c:231)
==5309==    by 0x40073A: main (test-di-set.c:39)
==5309== 
==5309== LEAK SUMMARY:
==5309==    definitely lost: 96 bytes in 2 blocks
==5309==    indirectly lost: 20,464 bytes in 3 blocks
==5309==      possibly lost: 0 bytes in 0 blocks
==5309==    still reachable: 0 bytes in 0 blocks
==5309==         suppressed: 0 bytes in 0 blocks
==5309== 
==5309== For counts of detected and suppressed errors, rerun with: -v
==5309== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)


This patch fixes it.


2019-03-10  Bruno Haible  <address@hidden>

        di-set: Fix memory leak.
        * lib/di-set.c (di_set_free): Free the ino_map through ino_map_free(),
        not free().

diff --git a/lib/di-set.c b/lib/di-set.c
index e8f69db..2c0601e 100644
--- a/lib/di-set.c
+++ b/lib/di-set.c
@@ -136,7 +136,7 @@ void
 di_set_free (struct di_set *dis)
 {
   hash_free (dis->dev_map);
-  free (dis->ino_map);
+  ino_map_free (dis->ino_map);
   free (dis->probe);
   free (dis);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]