* memory leak in bitset
@ 2019-03-10 13:27 Bruno Haible
2019-03-19 20:45 ` Akim Demaille
0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2019-03-10 13:27 UTC (permalink / raw)
To: bug-gnulib, Akim Demaille
Hi Akim,
There is apparently a memory leak in the 'bitset' module. After I modified
'test-bitset.c' to free the allocated bitsets, "gcc -fsanitize=leak" and
valgrind still report lost memory allocations.
"gcc -fsanitize=leak" reports:
ERROR: LeakSanitizer: detected memory leaks
Direct leak of 376 byte(s) in 27 object(s) allocated from:
#0 0x7ff0f00179d4 in __interceptor_realloc ../../../../gcc-8.2.0/libsanitizer/lsan/lsan_interceptors.cc:80
#1 0x40b3d8 in vbitset_resize ../../gllib/bitset/vector.c:77
SUMMARY: LeakSanitizer: 376 byte(s) leaked in 27 allocation(s).
FAIL test-bitset (exit status: 23)
valgrind reports:
==8212== HEAP SUMMARY:
==8212== in use at exit: 8,504 bytes in 29 blocks
==8212== total heap usage: 140 allocs, 111 frees, 13,920 bytes allocated
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 1 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4014A8: check_attributes (test-bitset.c:134)
==8212== by 0x400BE7: main (test-bitset.c:172)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 2 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4014F0: check_attributes (test-bitset.c:139)
==8212== by 0x400BE7: main (test-bitset.c:172)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 3 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401572: check_attributes (test-bitset.c:146)
==8212== by 0x400BE7: main (test-bitset.c:172)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 4 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4015E5: check_attributes (test-bitset.c:155)
==8212== by 0x400BE7: main (test-bitset.c:172)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 5 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4014A8: check_attributes (test-bitset.c:134)
==8212== by 0x400BF1: main (test-bitset.c:173)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 6 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4014F0: check_attributes (test-bitset.c:139)
==8212== by 0x400BF1: main (test-bitset.c:173)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 7 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401572: check_attributes (test-bitset.c:146)
==8212== by 0x400BF1: main (test-bitset.c:173)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 8 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4015E5: check_attributes (test-bitset.c:155)
==8212== by 0x400BF1: main (test-bitset.c:173)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 9 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4014A8: check_attributes (test-bitset.c:134)
==8212== by 0x400C05: main (test-bitset.c:175)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 10 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4014F0: check_attributes (test-bitset.c:139)
==8212== by 0x400C05: main (test-bitset.c:175)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 11 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401572: check_attributes (test-bitset.c:146)
==8212== by 0x400C05: main (test-bitset.c:175)
==8212==
==8212== 8 bytes in 1 blocks are definitely lost in loss record 12 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x4015E5: check_attributes (test-bitset.c:155)
==8212== by 0x400C05: main (test-bitset.c:175)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 13 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FA9: compare (test-bitset.c:55)
==8212== by 0x400C2D: main (test-bitset.c:179)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 14 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FC3: compare (test-bitset.c:57)
==8212== by 0x400C2D: main (test-bitset.c:179)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 15 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FE2: compare (test-bitset.c:59)
==8212== by 0x400C2D: main (test-bitset.c:179)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 16 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401003: compare (test-bitset.c:61)
==8212== by 0x400C2D: main (test-bitset.c:179)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 17 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401024: compare (test-bitset.c:63)
==8212== by 0x400C2D: main (test-bitset.c:179)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 18 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FA9: compare (test-bitset.c:55)
==8212== by 0x400C3C: main (test-bitset.c:180)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 19 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FC3: compare (test-bitset.c:57)
==8212== by 0x400C3C: main (test-bitset.c:180)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 20 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FE2: compare (test-bitset.c:59)
==8212== by 0x400C3C: main (test-bitset.c:180)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 21 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401003: compare (test-bitset.c:61)
==8212== by 0x400C3C: main (test-bitset.c:180)
==8212==
==8212== 16 bytes in 1 blocks are definitely lost in loss record 22 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401024: compare (test-bitset.c:63)
==8212== by 0x400C3C: main (test-bitset.c:180)
==8212==
==8212== 24 bytes in 1 blocks are definitely lost in loss record 23 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FA9: compare (test-bitset.c:55)
==8212== by 0x400C5A: main (test-bitset.c:182)
==8212==
==8212== 24 bytes in 1 blocks are definitely lost in loss record 24 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FC3: compare (test-bitset.c:57)
==8212== by 0x400C5A: main (test-bitset.c:182)
==8212==
==8212== 24 bytes in 1 blocks are definitely lost in loss record 25 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x400FE2: compare (test-bitset.c:59)
==8212== by 0x400C5A: main (test-bitset.c:182)
==8212==
==8212== 24 bytes in 1 blocks are definitely lost in loss record 26 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401003: compare (test-bitset.c:61)
==8212== by 0x400C5A: main (test-bitset.c:182)
==8212==
==8212== 24 bytes in 1 blocks are definitely lost in loss record 27 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40B7F8: vbitset_resize (vector.c:77)
==8212== by 0x40C66F: vbitset_init (vector.c:983)
==8212== by 0x401024: compare (test-bitset.c:63)
==8212== by 0x400C5A: main (test-bitset.c:182)
==8212==
==8212== 4,064 bytes in 1 blocks are still reachable in loss record 28 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40C688: xmalloc (xmalloc.c:41)
==8212== by 0x40C9AF: _obstack_begin_worker (obstack.c:136)
==8212== by 0x408121: lbitset_elt_alloc (list.c:129)
==8212== by 0x408121: lbitset_elt_calloc (list.c:149)
==8212== by 0x408121: lbitset_elt_find (list.c:366)
==8212== by 0x4081ED: lbitset_set (list.c:503)
==8212== by 0x40166C: bitset_set (bitset.h:143)
==8212== by 0x40166C: check_attributes (test-bitset.c:140)
==8212== by 0x400BFB: main (test-bitset.c:174)
==8212==
==8212== 4,064 bytes in 1 blocks are still reachable in loss record 29 of 29
==8212== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8212== by 0x40C688: xmalloc (xmalloc.c:41)
==8212== by 0x40C9AF: _obstack_begin_worker (obstack.c:136)
==8212== by 0x4054C1: tbitset_elt_alloc (table.c:208)
==8212== by 0x4054C1: tbitset_elt_calloc (table.c:228)
==8212== by 0x4054C1: tbitset_elt_find (table.c:311)
==8212== by 0x405775: tbitset_set (table.c:474)
==8212== by 0x40166C: bitset_set (bitset.h:143)
==8212== by 0x40166C: check_attributes (test-bitset.c:140)
==8212== by 0x400C0F: main (test-bitset.c:176)
==8212==
==8212== LEAK SUMMARY:
==8212== definitely lost: 376 bytes in 27 blocks
==8212== indirectly lost: 0 bytes in 0 blocks
==8212== possibly lost: 0 bytes in 0 blocks
==8212== still reachable: 8,128 bytes in 2 blocks
==8212== suppressed: 0 bytes in 0 blocks
==8212==
==8212== For counts of detected and suppressed errors, rerun with: -v
==8212== ERROR SUMMARY: 27 errors from 27 contexts (suppressed: 0 from 0)
Bruno
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: memory leak in bitset
2019-03-10 13:27 memory leak in bitset Bruno Haible
@ 2019-03-19 20:45 ` Akim Demaille
0 siblings, 0 replies; 2+ messages in thread
From: Akim Demaille @ 2019-03-19 20:45 UTC (permalink / raw)
To: Bruno Haible; +Cc: bug-gnulib
Hi Bruno,
> Le 10 mars 2019 à 14:27, Bruno Haible <bruno@clisp.org> a écrit :
>
> Hi Akim,
>
> There is apparently a memory leak in the 'bitset' module. After I modified
> 'test-bitset.c' to free the allocated bitsets, "gcc -fsanitize=leak" and
> valgrind still report lost memory allocations.
>
>
> "gcc -fsanitize=leak" reports:
>
> ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 376 byte(s) in 27 object(s) allocated from:
> #0 0x7ff0f00179d4 in __interceptor_realloc ../../../../gcc-8.2.0/libsanitizer/lsan/lsan_interceptors.cc:80
> #1 0x40b3d8 in vbitset_resize ../../gllib/bitset/vector.c:77
>
> SUMMARY: LeakSanitizer: 376 byte(s) leaked in 27 allocation(s).
> FAIL test-bitset (exit status: 23)
Good catch, thanks!
In two patches. A stylistic one, then the actual fix. Cheers!
commit 7e957a8a54a798cc8367b8e7ad0b8ad79c512be1
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Tue Mar 19 21:26:35 2019 +0100
bitset: minor changes
* lib/bitset/base.h (bitset_alloc_type): Remove, unused.
* lib/bitset/table.c: Formatting changes.
Remove useless braces.
Prefer using else in cascades of if/else-if with returns.
* lib/bitset/vector.c: Reduce scopes.
diff --git a/ChangeLog b/ChangeLog
index e842813d1..d0049e3c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-03-19 Akim Demaille <akim@lrde.epita.fr>
+
+ bitset: minor changes
+ * lib/bitset/base.h (bitset_alloc_type): Remove, unused.
+ * lib/bitset/table.c: Formatting changes.
+ Remove useless braces.
+ Prefer using else in cascades of if/else-if with returns.
+ * lib/bitset/vector.c: Reduce scopes.
+
2019-03-19 Akim Demaille <akim@lrde.epita.fr>
bitset: expose bitset_resize
diff --git a/lib/bitset/base.h b/lib/bitset/base.h
index 4fcafac8b..fe1b8fbe1 100644
--- a/lib/bitset/base.h
+++ b/lib/bitset/base.h
@@ -55,8 +55,6 @@ enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_VECTOR,
extern const char * const bitset_type_names[];
-enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};
-
/* Data type used to store a word of bits. */
typedef unsigned long bitset_word;
#define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word)))
diff --git a/lib/bitset/table.c b/lib/bitset/table.c
index 9cac96469..07184d657 100644
--- a/lib/bitset/table.c
+++ b/lib/bitset/table.c
@@ -188,21 +188,21 @@ tbitset_elt_alloc (void)
/* Let particular systems override the size of a chunk. */
#ifndef OBSTACK_CHUNK_SIZE
-#define OBSTACK_CHUNK_SIZE 0
+# define OBSTACK_CHUNK_SIZE 0
#endif
/* Let them override the alloc and free routines too. */
#ifndef OBSTACK_CHUNK_ALLOC
-#define OBSTACK_CHUNK_ALLOC xmalloc
+# define OBSTACK_CHUNK_ALLOC xmalloc
#endif
#ifndef OBSTACK_CHUNK_FREE
-#define OBSTACK_CHUNK_FREE free
+# define OBSTACK_CHUNK_FREE free
#endif
#if ! defined __GNUC__ || __GNUC__ < 2
-#define __alignof__(type) 0
+# define __alignof__(type) 0
#endif
obstack_specify_allocation (&tbitset_obstack, OBSTACK_CHUNK_SIZE,
@@ -1018,13 +1018,9 @@ tbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
}
if (!tbitset_elt_zero_p (delt))
- {
- tbitset_elt_add (dst, delt, j);
- }
+ tbitset_elt_add (dst, delt, j);
else
- {
- tbitset_elt_free (delt);
- }
+ tbitset_elt_free (delt);
}
/* If we have elements of DST left over, free them all. */
@@ -1059,7 +1055,8 @@ tbitset_and_cmp (bitset dst, bitset src1, bitset src2)
tbitset_zero (dst);
return changed;
}
- return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
+ else
+ return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
}
@@ -1074,9 +1071,7 @@ static bool
tbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
{
if (EBITSET_ZERO_P (src2))
- {
- return tbitset_copy_cmp (dst, src1);
- }
+ return tbitset_copy_cmp (dst, src1);
else if (EBITSET_ZERO_P (src1))
{
tbitset_weed (dst);
@@ -1084,7 +1079,8 @@ tbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
tbitset_zero (dst);
return changed;
}
- return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
+ else
+ return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
}
@@ -1099,14 +1095,11 @@ static bool
tbitset_or_cmp (bitset dst, bitset src1, bitset src2)
{
if (EBITSET_ZERO_P (src2))
- {
- return tbitset_copy_cmp (dst, src1);
- }
+ return tbitset_copy_cmp (dst, src1);
else if (EBITSET_ZERO_P (src1))
- {
- return tbitset_copy_cmp (dst, src2);
- }
- return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
+ return tbitset_copy_cmp (dst, src2);
+ else
+ return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
}
@@ -1121,14 +1114,11 @@ static bool
tbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
{
if (EBITSET_ZERO_P (src2))
- {
- return tbitset_copy_cmp (dst, src1);
- }
+ return tbitset_copy_cmp (dst, src1);
else if (EBITSET_ZERO_P (src1))
- {
- return tbitset_copy_cmp (dst, src2);
- }
- return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
+ return tbitset_copy_cmp (dst, src2);
+ else
+ return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
}
diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c
index 15d3e9956..0623651dc 100644
--- a/lib/bitset/vector.c
+++ b/lib/bitset/vector.c
@@ -467,7 +467,6 @@ vbitset_and (bitset dst, bitset src1, bitset src2)
static bool
vbitset_and_cmp (bitset dst, bitset src1, bitset src2)
{
- bool changed = false;
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
bitset_windex dsize = VBITSET_SIZE (dst);
@@ -477,6 +476,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2)
bitset_word *src1p = VBITSET_WORDS (src1);
bitset_word *src2p = VBITSET_WORDS (src2);
+ bool changed = false;
unsigned i;
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
@@ -546,7 +546,6 @@ vbitset_andn (bitset dst, bitset src1, bitset src2)
static bool
vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
{
- bool changed = false;
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
bitset_windex dsize = VBITSET_SIZE (dst);
@@ -556,6 +555,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
bitset_word *src1p = VBITSET_WORDS (src1);
bitset_word *src2p = VBITSET_WORDS (src2);
+ bool changed = false;
unsigned i;
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
@@ -633,8 +633,6 @@ vbitset_or (bitset dst, bitset src1, bitset src2)
static bool
vbitset_or_cmp (bitset dst, bitset src1, bitset src2)
{
- bool changed = false;
-
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
bitset_windex dsize = VBITSET_SIZE (dst);
@@ -644,6 +642,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2)
bitset_word *src1p = VBITSET_WORDS (src1);
bitset_word *src2p = VBITSET_WORDS (src2);
+ bool changed = false;
unsigned i;
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
@@ -711,7 +710,6 @@ vbitset_xor (bitset dst, bitset src1, bitset src2)
static bool
vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
{
- bool changed = false;
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
bitset_windex dsize = VBITSET_SIZE (dst);
@@ -721,6 +719,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
bitset_word *src1p = VBITSET_WORDS (src1);
bitset_word *src2p = VBITSET_WORDS (src2);
+ bool changed = false;
unsigned i;
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
@@ -903,8 +902,8 @@ vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
bitset_word *dstp = VBITSET_WORDS (dst);
bitset_windex size = VBITSET_SIZE (dst);
- unsigned i;
bool changed = false;
+ unsigned i;
for (i = 0; i < size; i++, dstp++)
{
bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
commit bbc77d41000305aed9fd022106eb1f46803dc25c
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Tue Mar 19 21:38:00 2019 +0100
bitset: fix memory leaks
Reported by Bruno Haible.
https://lists.gnu.org/archive/html/bug-gnulib/2019-03/msg00027.html
* lib/bitset/vector.c (vbitset_free): New.
(vbitset_vtable): Use it.
diff --git a/ChangeLog b/ChangeLog
index d0049e3c4..9a1698598 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-03-19 Akim Demaille <akim@lrde.epita.fr>
+
+ bitset: fix memory leaks
+ Reported by Bruno Haible.
+ https://lists.gnu.org/archive/html/bug-gnulib/2019-03/msg00027.html
+ * lib/bitset/vector.c (vbitset_free): New.
+ (vbitset_vtable): Use it.
+
2019-03-19 Akim Demaille <akim@lrde.epita.fr>
bitset: minor changes
diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c
index 0623651dc..54f148d56 100644
--- a/lib/bitset/vector.c
+++ b/lib/bitset/vector.c
@@ -928,6 +928,13 @@ vbitset_copy (bitset dst, bitset src)
}
+static void
+vbitset_free (bitset bset)
+{
+ free (VBITSET_WORDS (bset));
+}
+
+
/* Vector of operations for multiple word bitsets. */
struct bitset_vtable vbitset_vtable = {
vbitset_set,
@@ -961,7 +968,7 @@ struct bitset_vtable vbitset_vtable = {
vbitset_or_and_cmp,
vbitset_list,
vbitset_list_reverse,
- NULL,
+ vbitset_free,
BITSET_VECTOR
};
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-03-19 21:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-10 13:27 memory leak in bitset Bruno Haible
2019-03-19 20:45 ` Akim Demaille
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).