main.c
只...
int main(void)
{
return 0;
}
执行......
gcc `pkg-config --cflags --libs glib-2.0` -W -Wall -Wextra main.c -o out
编译成可执行文件......
out
执行......
valgrind --show-leak-kinds=all --leak-check=full -v ./out
给我 ...
==6404== Memcheck, a memory error detector
==6404== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==6404== Using Valgrind-3.14.0-3a3000290b-20181009X and LibVEX; rerun with -h for copyright info
==6404== Command: ./out
==6404==
--6404-- Valgrind options:
--6404-- --show-leak-kinds=all
--6404-- --leak-check=full
--6404-- -v
--6404-- Contents of /proc/version:
--6404-- Linux version 4.19.28-1-MANJARO (builduser@development) (gcc version 8.2.1 20181127 (GCC)) #1 SMP PREEMPT Sun Mar 10 08:32:42 UTC 2019
--6404--
--6404-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-avx-avx2-bmi
--6404-- Page sizes: currently 4096, max supported 4096
--6404-- Valgrind library directory: /usr/lib/valgrind
--6404-- Reading syms from /home/killbyte/Documents/Curso/LI3/tester-project-li3/out
--6404-- Reading syms from /usr/lib/ld-2.28.so
--6404-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux
--6404-- object doesn't have a dynamic symbol table
--6404-- Scheduler: using generic scheduler lock implementation.
--6404-- Reading suppressions file: /usr/lib/valgrind/default.supp
==6404== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-6404-by-killbyte-on-???
==6404== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-6404-by-killbyte-on-???
==6404== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-6404-by-killbyte-on-???
==6404==
==6404== TO CONTROL THIS PROCESS USING vgdb (which you probably
==6404== don't want to do, unless you know exactly what you're doing,
==6404== or are doing some strange experiment):
==6404== /usr/lib/valgrind/../../bin/vgdb --pid=6404 ...command...
==6404==
==6404== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==6404== /path/to/gdb ./out
==6404== and then give GDB the following command
==6404== target remote | /usr/lib/valgrind/../../bin/vgdb --pid=6404
==6404== --pid is optional if only one valgrind process is running
==6404==
--6404-- REDIR: 0x401ff20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9742 (vgPlain_amd64_linux_REDIR_FOR_strlen)
--6404-- REDIR: 0x401fcf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c975c (vgPlain_amd64_linux_REDIR_FOR_index)
--6404-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so
--6404-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
==6404== WARNING: new redirection conflicts with existing -- ignoring it
--6404-- old: 0x0401ff20 (strlen ) R-> (0000.0) 0x580c9742 vgPlain_amd64_linux_REDIR_FOR_strlen
--6404-- new: 0x0401ff20 (strlen ) R-> (2007.0) 0x0483ad80 strlen
--6404-- REDIR: 0x401c700 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483be40 (strcmp)
--6404-- REDIR: 0x4020480 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x483f860 (mempcpy)
--6404-- Reading syms from /usr/lib/libglib-2.0.so.0.5800.3
--6404-- object doesn't have a symbol table
--6404-- Reading syms from /usr/lib/libc-2.28.so
--6404-- Reading syms from /usr/lib/libpthread-2.28.so
--6404-- Reading syms from /usr/lib/libpcre.so.1.2.11
--6404-- object doesn't have a symbol table
--6404-- REDIR: 0x4a23060 (libc.so.6:strchrnul) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a3b800 (libc.so.6:wcslen) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a27b10 (libc.so.6:memrchr) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a3cf90 (libc.so.6:wcsnlen) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21b70 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21a20 (libc.so.6:strncasecmp) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a216c0 (libc.so.6:memmove) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
==6404== Preferring higher priority redirection:
--6404-- old: 0x04af6c60 (__memcpy_avx_unalign) R-> (2018.0) 0x0483c300 memcpy@@GLIBC_2.14
--6404-- new: 0x04af6c60 (__memcpy_avx_unalign) R-> (2018.1) 0x0483e8a0 memmove
--6404-- REDIR: 0x4a20840 (libc.so.6:strncpy) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a219d0 (libc.so.6:strcasecmp) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20210 (libc.so.6:strcat) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20880 (libc.so.6:rindex) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a23030 (libc.so.6:rawmemchr) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a3bca0 (libc.so.6:wmemchr) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a3b700 (libc.so.6:wcscmp) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21830 (libc.so.6:mempcpy) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21650 (libc.so.6:bcmp) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a207e0 (libc.so.6:strncmp) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20290 (libc.so.6:strcmp) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21790 (libc.so.6:memset) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a3b6d0 (libc.so.6:wcschr) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20770 (libc.so.6:strnlen) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20340 (libc.so.6:strcspn) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20300 (libc.so.6:strcpy) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a208b0 (libc.so.6:strpbrk) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20250 (libc.so.6:index) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20740 (libc.so.6:strlen) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21a70 (libc.so.6:strcasecmp_l) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21620 (libc.so.6:memchr) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a20b70 (libc.so.6:strspn) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21990 (libc.so.6:stpncpy) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21950 (libc.so.6:stpcpy) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21ac0 (libc.so.6:strncasecmp_l) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4aa1380 (libc.so.6:__memcpy_chk) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4a21540 (libc.so.6:strstr) redirected to 0x482d1c0 (_vgnU_ifunc_wrapper)
--6404-- REDIR: 0x4af6530 (libc.so.6:__strrchr_avx2) redirected to 0x483a790 (rindex)
--6404-- REDIR: 0x4af6700 (libc.so.6:__strlen_avx2) redirected to 0x483ac60 (strlen)
--6404-- REDIR: 0x4a1c8d0 (libc.so.6:malloc) redirected to 0x4837710 (malloc)
--6404-- REDIR: 0x4a1d6b0 (libc.so.6:calloc) redirected to 0x4839ab0 (calloc)
--6404-- REDIR: 0x4a1cf20 (libc.so.6:free) redirected to 0x4838940 (free)
==6404==
==6404== HEAP SUMMARY:
==6404== in use at exit: 18,604 bytes in 6 blocks
==6404== total heap usage: 6 allocs, 0 frees, 18,604 bytes allocated
==6404==
==6404== Searching for pointers to 6 not-freed blocks
==6404== Checked 101,040 bytes
==6404==
==6404== 4 bytes in 1 blocks are still reachable in loss record 1 of 6
==6404== at 0x483777F: malloc (vg_replace_malloc.c:299)
==6404== by 0x488F5C3: ??? (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x488F6BB: g_private_get (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48B906D: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48F4CDE: g_hash_table_new_full (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48CE533: ??? (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x4010549: call_init.part.0 (in /usr/lib/ld-2.28.so)
==6404== by 0x4010649: _dl_init (in /usr/lib/ld-2.28.so)
==6404== by 0x4002039: ??? (in /usr/lib/ld-2.28.so)
==6404==
==6404== 32 bytes in 1 blocks are still reachable in loss record 2 of 6
==6404== at 0x4839B65: calloc (vg_replace_malloc.c:752)
==6404== by 0x48D8839: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48F4D47: g_hash_table_new_full (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48CE533: ??? (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x4010549: call_init.part.0 (in /usr/lib/ld-2.28.so)
==6404== by 0x4010649: _dl_init (in /usr/lib/ld-2.28.so)
==6404== by 0x4002039: ??? (in /usr/lib/ld-2.28.so)
==6404==
==6404== 64 bytes in 1 blocks are still reachable in loss record 3 of 6
==6404== at 0x4839B65: calloc (vg_replace_malloc.c:752)
==6404== by 0x48D8839: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48F4D31: g_hash_table_new_full (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48CE533: ??? (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x4010549: call_init.part.0 (in /usr/lib/ld-2.28.so)
==6404== by 0x4010649: _dl_init (in /usr/lib/ld-2.28.so)
==6404== by 0x4002039: ??? (in /usr/lib/ld-2.28.so)
==6404==
==6404== 88 bytes in 1 blocks are still reachable in loss record 4 of 6
==6404== at 0x483777F: malloc (vg_replace_malloc.c:299)
==6404== by 0x48D88D1: g_malloc (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48B9094: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48F4CDE: g_hash_table_new_full (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48CE533: ??? (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x4010549: call_init.part.0 (in /usr/lib/ld-2.28.so)
==6404== by 0x4010649: _dl_init (in /usr/lib/ld-2.28.so)
==6404== by 0x4002039: ??? (in /usr/lib/ld-2.28.so)
==6404==
==6404== 2,032 bytes in 1 blocks are still reachable in loss record 5 of 6
==6404== at 0x4839B65: calloc (vg_replace_malloc.c:752)
==6404== by 0x48D8839: g_malloc0 (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48B92EE: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48F4CDE: g_hash_table_new_full (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48CE533: ??? (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x4010549: call_init.part.0 (in /usr/lib/ld-2.28.so)
==6404== by 0x4010649: _dl_init (in /usr/lib/ld-2.28.so)
==6404== by 0x4002039: ??? (in /usr/lib/ld-2.28.so)
==6404==
==6404== 16,384 bytes in 1 blocks are still reachable in loss record 6 of 6
==6404== at 0x483777F: malloc (vg_replace_malloc.c:299)
==6404== by 0x48D88D1: g_malloc (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x48CE545: ??? (in /usr/lib/libglib-2.0.so.0.5800.3)
==6404== by 0x4010549: call_init.part.0 (in /usr/lib/ld-2.28.so)
==6404== by 0x4010649: _dl_init (in /usr/lib/ld-2.28.so)
==6404== by 0x4002039: ??? (in /usr/lib/ld-2.28.so)
==6404==
==6404== LEAK SUMMARY:
==6404== definitely lost: 0 bytes in 0 blocks
==6404== indirectly lost: 0 bytes in 0 blocks
==6404== possibly lost: 0 bytes in 0 blocks
==6404== still reachable: 18,604 bytes in 6 blocks
==6404== suppressed: 0 bytes in 0 blocks
==6404==
==6404== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==6404== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
问题是valgrind告诉我泄漏汇总still reachable: 18,604 bytes in 6 blocks
我甚至没有任何代码......甚至没有#include
正如Ctx在评论中所说,这些分配是在GLib的库构造函数中完成的,在输入main()
函数之前会自动调用。它们在生命周期中完成一次,以分配各种内部结构和缓存。
如果你在glib.supp
中使用GLib安装的/usr/share/glib-2.0/valgrind/glib.supp
抑制文件,它们应该被禁止。如果没有,请file a bug against GLib。