- 論壇徽章:
- 0
|
初次使用Glib,代碼基本寫完之后,順手測試下,發(fā)現(xiàn)
GHashTable內存泄漏問題,不知是否使用方式不對?
另:g_key_file_new .. g_key_file_load_from_file ... g_key_file_free 同樣問題。。
精簡后最小測試代碼如下:
#include <glib.h>
int main(int argc,char **argv){
printf("glib version = %d.%d.%d\n",glib_major_version,glib_minor_version,glib_micro_version);
GHashTable *h = g_hash_table_new(NULL,NULL);
g_hash_table_destroy(h);
}
編譯后運行之
valgrind --db-attach=yes --tool=memcheck --leak-check=full --show-leak-kinds=all ./test.bin
glib version = 2.40.2
==27702== HEAP SUMMARY:
==27702== in use at exit: 2,076 bytes in 3 blocks
==27702== total heap usage: 6 allocs, 3 frees, 2,260 bytes allocated
==27702==
==27702== 4 bytes in 1 blocks are still reachable in loss record 1 of 3
==27702== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27702== by 0x56B08CD: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x56B0D28: g_private_get (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x568A20C: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x565E17D: g_hash_table_new_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x4019E0: do_test_ini (test.c:122)
==27702== by 0x40157A: main (test.c:24)
==27702==
==27702== 40 bytes in 1 blocks are still reachable in loss record 2 of 3
==27702== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27702== by 0x56B058F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x56B0634: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x56B0978: g_mutex_lock (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x5640D71: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x568A374: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x565E17D: g_hash_table_new_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x4019E0: do_test_ini (test.c:122)
==27702== by 0x40157A: main (test.c:24)
==27702==
==27702== 2,032 bytes in 1 blocks are still reachable in loss record 3 of 3
==27702== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27702== by 0x5674668: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x5641015: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x568A374: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x565E17D: g_hash_table_new_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
==27702== by 0x4019E0: do_test_ini (test.c:122)
==27702== by 0x40157A: main (test.c:24)
==27702==
==27702== LEAK SUMMARY:
==27702== definitely lost: 0 bytes in 0 blocks
==27702== indirectly lost: 0 bytes in 0 blocks
==27702== possibly lost: 0 bytes in 0 blocks
==27702== still reachable: 2,076 bytes in 3 blocks
==27702== suppressed: 0 bytes in 0 blocks
==27702==
==27702== For counts of detected and suppressed errors, rerun with: -v
==27702== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
|
|