我最近和valgrind一起出现了一些奇怪的事。如果我写一个简单的#include <stdio.h>
#include <stdlib.h>
int main(){
printf("hello\n");
}
文件:
gcc $(pkg-config --cflags --libs gtk+-3.0) -g3 -O0
并使用以下命令编译它:valgrind --leak-check=full ./a.out
然后检查内存泄漏:==7588== Memcheck, a memory error detector
==7588== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==7588== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==7588== Command: ./a.out
==7588==
hello
==7588==
==7588== HEAP SUMMARY:
==7588== in use at exit: 51,837 bytes in 245 blocks
==7588== total heap usage: 1,551 allocs, 1,306 frees, 394,322,404 bytes allocated
==7588==
==7588== 16 bytes in 1 blocks are possibly lost in loss record 89 of 244
==7588== at 0x4C2A987: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7588== by 0x6DE35B1: g_malloc0 (in /usr/lib/libglib-2.0.so.0.4400.1)
==7588== by 0x6B70294: ??? (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x6B73F92: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x6B5464B: ??? (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x6B4E67D: ??? (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x400F279: call_init.part.0 (in /usr/lib/ld-2.22.so)
==7588== by 0x400F38A: _dl_init (in /usr/lib/ld-2.22.so)
==7588== by 0x4000DB9: ??? (in /usr/lib/ld-2.22.so)
==7588==
==7588== 16 bytes in 1 blocks are possibly lost in loss record 90 of 244
==7588== at 0x4C28C10: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7588== by 0x4C2AADE: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7588== by 0x6DE361D: g_realloc (in /usr/lib/libglib-2.0.so.0.4400.1)
==7588== by 0x6B70148: ??? (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x6B73F92: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x6B5464B: ??? (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x6B4E67D: ??? (in /usr/lib/libgobject-2.0.so.0.4400.1)
==7588== by 0x400F279: call_init.part.0 (in /usr/lib/ld-2.22.so)
==7588== by 0x400F38A: _dl_init (in /usr/lib/ld-2.22.so)
==7588== by 0x4000DB9: ??? (in /usr/lib/ld-2.22.so)
==7588==
.
.
.
==7588==
==7588== LEAK SUMMARY:
==7588== definitely lost: 0 bytes in 0 blocks
==7588== indirectly lost: 0 bytes in 0 blocks
==7588== possibly lost: 1,352 bytes in 18 blocks
==7588== still reachable: 50,485 bytes in 227 blocks
==7588== of which reachable via heuristic:
==7588== newarray : 1,536 bytes in 16 blocks
==7588== suppressed: 0 bytes in 0 blocks
==7588== Reachable blocks (those to which a pointer was found) are not shown.
==7588== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==7588==
==7588== For counts of detected and suppressed errors, rerun with: -v
==7588== ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 0 from 0)
我得到类似的内容:
gcc -g3 -O0 test.c
然而,如果我正常编译它,使用:valgrind --leak-check=full ./a.out
,然后使用==7734== Memcheck, a memory error detector
==7734== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==7734== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==7734== Command: ./a.out
==7734==
hello
==7734==
==7734== HEAP SUMMARY:
==7734== in use at exit: 0 bytes in 0 blocks
==7734== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==7734==
==7734== All heap blocks were freed -- no leaks are possible
==7734==
==7734== For counts of detected and suppressed errors, rerun with: -v
==7734== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
检查内存泄漏,我显然没有任何内存泄漏:
{{1}}
所以我的问题是:为什么链接gtk会产生如此多的内存泄漏?
非常感谢您提前