C ++ valgrind内存泄漏即使内存显然在链表中被释放

时间:2017-05-03 18:33:44

标签: c++ memory memory-leaks linked-list

我正在重新研究链表,我写了下面这段代码:

5320== Memcheck, a memory error detector
5320== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
5320== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
5320== Command: ./linked_list
5320== 
5320-- Valgrind options:
5320--    -v
5320--    --leak-check=full
5320--    --show-leak-kinds=all
5320-- Contents of /proc/version:
5320--   Linux version 3.2.0-105-generic (buildd@lgw01-13) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #146-Ubuntu SMP Fri Jun 10 20:10:44 UTC 2016
5320-- 
5320-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-avx
5320-- Page sizes: currently 4096, max supported 4096
5320-- Valgrind library directory: /usr/local/lib/valgrind
5320-- Reading syms from /home/crossi/workspace/linked_list
5320-- Reading syms from /lib/x86_64-linux-gnu/ld-2.15.so
5320--   Considering /lib/x86_64-linux-gnu/ld-2.15.so ..
5320--   .. CRC mismatch (computed 8de5d814 wanted 5f52208d)
5320--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.15.so ..
5320--   .. CRC is valid
5320-- Reading syms from /usr/local/lib/valgrind/memcheck-amd64-linux
5320--    object doesn't have a dynamic symbol table
5320-- Scheduler: using generic scheduler lock implementation.
5320-- Reading suppressions file: /usr/local/lib/valgrind/default.supp
5320== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-5320-by-crossi-on-???
5320== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-5320-by-crossi-on-???
5320== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-5320-by-crossi-on-???
5320== 
5320== TO CONTROL THIS PROCESS USING vgdb (which you probably
5320== don't want to do, unless you know exactly what you're doing,
5320== or are doing some strange experiment):
5320==   /usr/local/lib/valgrind/../../bin/vgdb --pid=5320 ...command...
5320== 
5320== TO DEBUG THIS PROCESS USING GDB: start GDB like this
5320==   /path/to/gdb ./linked_list
5320== and then give GDB the following command
5320==   target remote | /usr/local/lib/valgrind/../../bin/vgdb --pid=5320
5320== --pid is optional if only one valgrind process is running
5320== 
5320-- REDIR: 0x40189a0 (ld-linux-x86-64.so.2:strlen) redirected to 0x380576c1 (vgPlain_amd64_linux_REDIR_FOR_strlen)
5320-- Reading syms from /usr/local/lib/valgrind/vgpreload_core-amd64-linux.so
5320-- Reading syms from /usr/local/lib/valgrind/vgpreload_memcheck-amd64-linux.so
5320== WARNING: new redirection conflicts with existing -- ignoring it
5320--     old: 0x040189a0 (strlen              ) R-> (0000.0) 0x380576c1 vgPlain_amd64_linux_REDIR_FOR_strlen
5320--     new: 0x040189a0 (strlen              ) R-> (2007.0) 0x04c2db40 strlen
5320-- REDIR: 0x4018810 (ld-linux-x86-64.so.2:index) redirected to 0x4c2d740 (index)
5320-- REDIR: 0x4018890 (ld-linux-x86-64.so.2:strcmp) redirected to 0x4c2ece0 (strcmp)
5320-- REDIR: 0x4019a60 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4c31cb0 (mempcpy)
5320-- Reading syms from /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
5320--   Considering /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 ..
5320--   .. CRC mismatch (computed 61d0ac08 wanted 31a5e6a2)
5320--    object doesn't have a symbol table
5320-- Reading syms from /lib/x86_64-linux-gnu/libgcc_s.so.1
5320--   Considering /lib/x86_64-linux-gnu/libgcc_s.so.1 ..
5320--   .. CRC mismatch (computed a912abb1 wanted 680ea03d)
5320--    object doesn't have a symbol table
5320-- Reading syms from /lib/x86_64-linux-gnu/libc-2.15.so
5320--   Considering /lib/x86_64-linux-gnu/libc-2.15.so ..
5320--   .. CRC mismatch (computed 9cf0cdc3 wanted 1943e04b)
5320--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.15.so ..
5320--   .. CRC is valid
5320-- Reading syms from /lib/x86_64-linux-gnu/libm-2.15.so
5320--   Considering /lib/x86_64-linux-gnu/libm-2.15.so ..
5320--   .. CRC mismatch (computed 04e8de65 wanted 200e7c12)
5320--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/libm-2.15.so ..
5320--   .. CRC is valid
5320-- REDIR: 0x53ebd60 (libc.so.6:strcasecmp) redirected to 0x4a2560a (_vgnU_ifunc_wrapper)
5320-- REDIR: 0x53e8100 (libc.so.6:strnlen) redirected to 0x4a2560a (_vgnU_ifunc_wrapper)
5320-- REDIR: 0x53ee030 (libc.so.6:strncasecmp) redirected to 0x4a2560a (_vgnU_ifunc_wrapper)
5320-- REDIR: 0x53e9af0 (libc.so.6:__GI_strrchr) redirected to 0x4c2d450 (__GI_strrchr)
5320-- REDIR: 0x53e1e10 (libc.so.6:malloc) redirected to 0x4c2cfa0 (malloc)
5320-- REDIR: 0x53e8020 (libc.so.6:__GI_strlen) redirected to 0x4c2daa0 (__GI_strlen)
5320-- REDIR: 0x53ea560 (libc.so.6:__GI_memcmp) redirected to 0x4c305f0 (__GI_memcmp)
5320-- REDIR: 0x53e64e0 (libc.so.6:strcmp) redirected to 0x4a2560a (_vgnU_ifunc_wrapper)
5320-- REDIR: 0x54911b0 (libc.so.6:__strcmp_sse42) redirected to 0x4c2ec80 (__strcmp_sse42)
5320-- REDIR: 0x53e7fd0 (libc.so.6:strlen) redirected to 0x4a2560a (_vgnU_ifunc_wrapper)
5320-- REDIR: 0x54c1f70 (libc.so.6:__strlen_sse2_pminub) redirected to 0x4c2da80 (strlen)
5320-- REDIR: 0x4ea0860 (libstdc++.so.6:operator new(unsigned long)) redirected to 0x4c2ca67 (operator new(unsigned long))
5320-- REDIR: 0x53f0710 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x4a2560a (_vgnU_ifunc_wrapper)
5320-- REDIR: 0x54a7330 (libc.so.6:__memcpy_ssse3_back) redirected to 0x4c2f0c0 (memcpy@@GLIBC_2.14)
5320-- REDIR: 0x53ea520 (libc.so.6:bcmp) redirected to 0x4a2560a (_vgnU_ifunc_wrapper)
5320-- REDIR: 0x54bc8a0 (libc.so.6:__memcmp_sse4_1) redirected to 0x4c30730 (__memcmp_sse4_1)
Print linked list:
Port Id:1 Name:node1
Port Id:2 Name:node2
Port Id:3 Name:node3
Port Id:4 Name:node4
Port Id:5 Name:node5
5320-- REDIR: 0x4e9e9b0 (libstdc++.so.6:operator delete(void*)) redirected to 0x4c2ba8c (operator delete(void*))
List is empty!
Print linked list:
Port Id:1 Name:node1
Port Id:2 Name:node2
Port Id:3 Name:node3
Port Id:4 Name:node4
Port Id:5 Name:node5
Print linked list:
Port Id:1 Name:node1
Port Id:2 Name:node2
Port Id:3 Name:node3
Port Id:4 Name:node4
Port Id:5 Name:node5
List is empty!
5320-- REDIR: 0x53e2420 (libc.so.6:free) redirected to 0x4c2bea6 (free)
5320== 
5320== HEAP SUMMARY:
5320==     in use at exit: 72,704 bytes in 1 blocks
5320==   total heap usage: 21 allocs, 20 frees, 73,244 bytes allocated
5320== 
5320== Searching for pointers to 1 not-freed blocks
5320== Checked 110,792 bytes
5320== 
5320== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
5320==    at 0x4C2D027: malloc (vg_replace_malloc.c:299)
5320==    by 0x4E9C9DF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22)
5320==    by 0x400F2C5: call_init.part.0 (dl-init.c:85)
5320==    by 0x400F39E: call_init (dl-init.c:52)
5320==    by 0x400F39E: _dl_init (dl-init.c:134)
5320==    by 0x40016E9: ??? (in /lib/x86_64-linux-gnu/ld-2.15.so)
5320== 
5320== LEAK SUMMARY:
5320==    definitely lost: 0 bytes in 0 blocks
5320==    indirectly lost: 0 bytes in 0 blocks
5320==      possibly lost: 0 bytes in 0 blocks
5320==    still reachable: 72,704 bytes in 1 blocks
5320==         suppressed: 0 bytes in 0 blocks
5320== 
5320== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
5320== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

然后我跑了valgrind: crossi @ devmachine:〜/ workspace $ valgrind -v --leak-check = full --show-leak-kinds = all ./linked_list

Uncaught TypeError: Cannot read property 'length' of undefined

有人知道这是否真的是内存泄漏以及内存未被释放的地方?

0 个答案:

没有答案