possible g_hash_table mem leak?



Hi there.
I've stumbled uppon some weird behavior of g_hash_table, maybe some
one can tell me if I wrong with this, or is this a real memory leak.
Here's a little c prog that demonstrates the problem:
====================
#include <glib.h>
void main(){
        GHashTable * h= g_hash_table_new_full  (
g_str_hash,g_str_equal, g_free,g_free);
        char *a,*b,*c,*d,*e,*f;
        asprintf(&a,"a");
        asprintf(&b,"b");
        g_hash_table_insert(h,a,b);
        g_hash_table_destroy (h);
}
====================
Compiled like this:
gcc `pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0`  leak.c

And after running valgring i get this:
reflog pcreflog /tmp $ valgrind  --show-reachable=yes
--leak-resolution=high  --tool=memcheck --leak-check=yes ./a.out
==28512== Memcheck, a memory error detector for x86-linux.
==28512== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==28512== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==28512== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==28512== For more details, rerun with: -v
==28512==
==28512==
==28512== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 1)
==28512== malloc/free: in use at exit: 1076 bytes in 2 blocks.
==28512== malloc/free: 8 allocs, 6 frees, 1352 bytes allocated.
==28512== For counts of detected errors, rerun with: -v
==28512== searching for pointers to 2 not-freed blocks.
==28512== checked 1873576 bytes.
==28512==
==28512== 52 bytes in 1 blocks are still reachable in loss record 1 of 2
==28512==    at 0x1B906BBD: malloc (vg_replace_malloc.c:131)
==28512==    by 0x1B9610A6: g_malloc (in /usr/lib/libglib-2.0.so.0.505.2)
==28512==    by 0x1B961BEA: g_mem_chunk_new (in /usr/lib/libglib-2.0.so.0.505.2)
==28512==    by 0x1B94F87B: (within /usr/lib/libglib-2.0.so.0.505.2)
==28512==
==28512==
==28512== 1024 bytes in 1 blocks are still reachable in loss record 2 of 2
==28512==    at 0x1B906BBD: malloc (vg_replace_malloc.c:131)
==28512==    by 0x1B9610A6: g_malloc (in /usr/lib/libglib-2.0.so.0.505.2)
==28512==    by 0x1B962091: g_mem_chunk_alloc (in
/usr/lib/libglib-2.0.so.0.505.2)
==28512==    by 0x1B94F888: (within /usr/lib/libglib-2.0.so.0.505.2)
==28512==
==28512== LEAK SUMMARY:
==28512==    definitely lost: 0 bytes in 0 blocks.
==28512==    possibly lost:   0 bytes in 0 blocks.
==28512==    still reachable: 1076 bytes in 2 blocks.
==28512==         suppressed: 0 bytes in 0 blocks.


And if i insert not one,but many items, the second leak becomes a real problem.


Any ideas?

Thanks in advance,

reflog

-- 
To err is human, to really screw things up - you need a computer.



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