我已经运行了以下命令并杀死了报告给它的所有泄漏和错误,但我仍然在程序完成执行后得到一些随机的free(): invalid pointer
。
valgrind -v --tool=memcheck --leak-check=full --track-origins=yes --show-reachable=yes ./blah
这是我修复“一切”后的输出:
--31313-- Discarding syms at 0x883f1f0-0x8847648 in /lib64/libnss_files-2.12.so due to munmap()
--31313-- Discarding syms at 0x8a4c000-0x8a4f328 in /lib64/libnss_dns-2.12.so due to munmap()
--31313-- Discarding syms at 0x8c54930-0x8c63938 in /lib64/libresolv-2.12.so due to munmap()
==31313==
==31313== HEAP SUMMARY:
==31313== in use at exit: 0 bytes in 0 blocks
==31313== total heap usage: 9,190 allocs, 9,190 frees, 1,286,890 bytes allocated
==31313==
==31313== All heap blocks were freed -- no leaks are possible
==31313==
==31313== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 6)
--31313--
--31313-- used_suppression: 6 U1004-ARM-_dl_relocate_object
--31313-- used_suppression: 2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a
==31313==
==31313== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 6)
还有什么我可以尝试跟踪这个随机+我的程序执行后,神秘无效免费?
编辑:
退出之前的最后2行......
applog("GODDAMN IT");
return final_rc;
}
这是我为free: invalid pointer
获得的“通知”:
GODDAMN IT
*** glibc detected *** ./scvpc: free(): invalid pointer: 0x00007f7975fbd6d0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x373e876166)[0x7f7974134166]
/home/svn/trunk/packages/wvstreams/libwvbase.so.5.2.0(_ZN12WvFastString6unlinkEv+0x1e)[0x7f7975d725be]
/home/svn/trunk/packages/wvstreams/libwvbase.so.5.2.0(_ZN8WvStreamD1Ev+0x491)[0x7f7975d81481]
/lib64/libc.so.6(__cxa_finalize+0x9d)[0x7f79740f41bd]
/home/svn/trunk/packages/wvstreams/libwvbase.so.5.2.0(+0x31e56)[0x7f7975d69e56]
======= Memory map: ========
7f796c000000-7f796c021000 rw-p 00000000 00:00 0
7f796c021000-7f7970000000 ---p 00000000 00:00 0
7f7972180000-7f7972196000 r-xp 00000000 fd:00 406206 /lib64/libresolv-2.12.so
7f7972196000-7f7972396000 ---p 00016000 fd:00 406206 /lib64/libresolv-2.12.so
7f7972396000-7f7972397000 r--p 00016000 fd:00 406206 /lib64/libresolv-2.12.so
7f7972397000-7f7972398000 rw-p 00017000 fd:00 406206 /lib64/libresolv-2.12.so
7f7972398000-7f797239a000 rw-p 00000000 00:00 0
7f797239a000-7f797239f000 r-xp 00000000 fd:00 390955 /lib64/libnss_dns-2.12.so
7f797239f000-7f797259e000 ---p 00005000 fd:00 390955 /lib64/libnss_dns-2.12.so
7f797259e000-7f797259f000 r--p 00004000 fd:00 390955 /lib64/libnss_dns-2.12.so
7f797259f000-7f79725a0000 rw-p 00005000 fd:00 390955 /lib64/libnss_dns-2.12.so
7f79725a0000-7f79725ac000 r-xp 00000000 fd:00 390957 /lib64/libnss_files-2.12.so
7f79725ac000-7f79727ac000 ---p 0000c000 fd:00 390957 /lib64/libnss_files-2.12.so
7f79727ac000-7f79727ad000 r--p 0000c000 fd:00 390957 /lib64/libnss_files-2.12.so
7f79727ad000-7f79727ae000 rw-p 0000d000 fd:00 390957 /lib64/libnss_files-2.12.so
7f79727ae000-7f79727af000 ---p 00000000 00:00 0
7f79727af000-7f79731af000 rw-p 00000000 00:00 0
7f79731af000-7f7973220000 r-xp 00000000 fd:00 392042 /lib64/libfreebl3.so
7f7973220000-7f797341f000 ---p 00071000 fd:00 392042 /lib64/libfreebl3.so
7f797341f000-7f7973421000 r--p 00070000 fd:00 392042 /lib64/libfreebl3.so
7f7973421000-7f7973422000 rw-p 00072000 fd:00 392042 /lib64/libfreebl3.so
7f7973422000-7f7973426000 rw-p 00000000 00:00 0
7f7973426000-7f797343d000 r-xp 00000000 fd:00 392038 /lib64/libaudit.so.1.0.0
7f797343d000-7f797363c000 ---p 00017000 fd:00 392038 /lib64/libaudit.so.1.0.0
7f797363c000-7f797363d000 r--p 00016000 fd:00 392038 /lib64/libaudit.so.1.0.0
7f797363d000-7f7973642000 rw-p 00017000 fd:00 392038 /lib64/libaudit.so.1.0.0
7f7973642000-7f7973644000 r-xp 00000000 fd:00 392041 /lib64/libdl-2.12.so
7f7973644000-7f7973844000 ---p 00002000 fd:00 392041 /lib64/libdl-2.12.so
7f7973844000-7f7973845000 r--p 00002000 fd:00 392041 /lib64/libdl-2.12.so
7f7973845000-7f7973846000 rw-p 00003000 fd:00 392041 /lib64/libdl-2.12.so
7f7973846000-7f797384d000 r-xp 00000000 fd:00 392043 /lib64/libcrypt-2.12.so
7f797384d000-7f7973a4d000 ---p 00007000 fd:00 392043 /lib64/libcrypt-2.12.so
7f7973a4d000-7f7973a4e000 r--p 00007000 fd:00 392043 /lib64/libcrypt-2.12.so
7f7973a4e000-7f7973a4f000 rw-p 00008000 fd:00 392043 /lib64/libcrypt-2.12.so
7f7973a4f000-7f7973a7d000 rw-p 00000000 00:00 0
7f7973a7d000-7f7973a89000 r-xp 00000000 fd:00 392044 /lib64/libpam.so.0.82.2
7f7973a89000-7f7973c89000 ---p 0000c000 fd:00 392044 /lib64/libpam.so.0.82.2
7f7973c89000-7f7973c8a000 r--p 0000c000 fd:00 392044 /lib64/libpam.so.0.82.2
7f7973c8a000-7f7973c8b000 rw-p 0000d000 fd:00 392044 /lib64/libpam.so.0.82.2
7f7973c8b000-7f7973ca2000 r-xp 00000000 fd:00 392046 /lib64/libpthread-2.12.so
7f7973ca2000-7f7973ea2000 ---p 00017000 fd:00 392046 /lib64/libpthread-2.12.so
7f7973ea2000-7f7973ea3000 r--p 00017000 fd:00 392046 /lib64/libpthread-2.12.so
7f7973ea3000-7f7973ea4000 rw-p 00018000 fd:00 392046 /lib64/libpthread-2.12.so
7f7973ea4000-7f7973ea8000 rw-p 00000000 00:00 0
7f7973ea8000-7f7973ebd000 r-xp 00000000 fd:00 392051 /lib64/libz.so.1.2.3
7f7973ebd000-7f79740bc000 ---p 00015000 fd:00 392051 /lib64/libz.so.1.2.3
7f79740bc000-7f79740bd000 r--p 00014000 fd:00 392051 /lib64/libz.so.1.2.3
7f79740bd000-7f79740be000 rw-p 00015000 fd:00 392051 /lib64/libz.so.1.2.3
7f79740be000-7f7974249000 r-xp 00000000 fd:00 391773 /lib64/libc-2.12.so
7f7974249000-7f7974448000 ---p 0018b000 fd:00 391773 /lib64/libc-2.12.so
7f7974448000-7f797444c000 r--p 0018a000 fd:00 391773 /lib64/libc-2.12.so
7f797444c000-7f797444d000 rw-p 0018e000 fd:00 391773 /lib64/libc-2.12.so
7f797444d000-7f7974452000 rw-p 00000000 00:00 0
7f7974452000-7f7974468000 r-xp 00000000 fd:00 392058 /lib64/libgcc_s-4.4.7-20120601.so.1
7f7974468000-7f7974667000 ---p 00016000 fd:00 392058 /lib64/libgcc_s-4.4.7-20120601.so.1
7f7974667000-7f7974668000 rw-p 00015000 fd:00 392058 /lib64/libgcc_s-4.4.7-20120601.so.1
7f7974668000-7f79746eb000 r-xp 00000000 fd:00 392052 /lib64/libm-2.12.so
7f79746eb000-7f79748ea000 ---p 00083000 fd:00 392052 /lib64/libm-2.12.so
7f79748ea000-7f79748eb000 r--p 00082000 fd:00 392052 /lib64/libm-2.12.so
7f79748eb000-7f79748ec000 rw-p 00083000 fd:00 392052 /lib64/libm-2.12.so
7f79748ec000-7f79749d4000 r-xp 00000000 fd:00 922734 /usr/lib64/libstdc++.so.6.0.13
7f79749d4000-7f7974bd4000 ---p 000e8000 fd:00 922734 /usr/lib64/libstdc++.so.6.0.13
7f7974bd4000-7f7974bdb000 r--p 000e8000 fd:00 922734 /usr/lib64/libstdc++.so.6.0.13
7f7974bdb000-7f7974bdd000 rw-p 000ef000 fd:00 922734 /usr/lib64/libstdc++.so.6.0.13
7f7974bdd000-7f7974bf2000 rw-p 00000000 00:00 0
7f7975084000-7f79750f3000 r-xp 00000000 fd:00 8662332 /home/svn/trunk/packages/openssl/libssl.so.1.0.1
7f79750f3000-7f79752f2000 ---p 0006f000 fd:00 8662332 /home/svn/trunk/packages/openssl/libssl.so.1.0.1
7f79752f2000-7f79752fb000 rw-p 0006e000 fd:00 8662332 /home/svn/trunk/packages/openssl/libssl.so.1.0.1
7f79752fb000-7f79754f2000 r-xp 00000000 fd:00 8662328 /home/svn/trunk/packages/openssl/libcrypto.so.1.0.1
7f79754f2000-7f79756f2000 ---p 001f7000 fd:00 8662328 /home/svn/trunk/packages/openssl/libcrypto.so.1.0.1
7f79756f2000-7f7975718000 rw-p 001f7000 fd:00 8662328 /home/svn/trunk/packages/openssl/libcrypto.so.1.0.1
7f7975718000-7f797571b000 rw-p 00000000 00:00 0
7f797571b000-7f7975742000 r-xp 00000000 fd:00 8867973 /home/svn/trunk/packages/wvstreams/libwvutils.so
7f7975742000-7f7975942000 ---p 00027000 fd:00 8867973 /home/svn/trunk/packages/wvstreams/libwvutils.so
7f7975942000-7f7975944000 rw-p 00027000 fd:00 8867973 /home/svn/trunk/packages/wvstreams/libwvutils.so
7f7975944000-7f7975a46000 rw-p 00000000 00:00 0
7f7975a46000-7f7975b2d000 r-xp 00000000 fd:00 8873068 /home/svn/trunk/packages/wvstreams/libwvstreams.so
7f7975b2d000-7f7975d2d000 ---p 000e7000 fd:00 8873068 /home/svn/trunk/packages/wvstreams/libwvstreams.so
7f7975d2d000-7f7975d38000 rw-p 000e7000 fd:00 8873068 /home/svn/trunk/packages/wvstreams/libwvstreams.so
7f7975d38000-7f7975db7000 r-xp 00000000 fd:00 8865320 /home/svn/trunk/packages/wvstreams/libwvbase.so
7f7975db7000-7f7975fb7000 ---p 0007f000 fd:00 8865320 /home/svn/trunk/packages/wvstreams/libwvbase.so
7f7975fb7000-7f7975fbe000 rw-p 0007f000 fd:00 8865320 /home/svn/trunk/packages/wvstreams/libwvbase.so
7f7975fbe000-7f7975fc2000 rw-p 00000000 00:00 0
7f7975fc2000-7f7975fe2000 r-xp 00000000 fd:00 391164 /lib64/ld-2.12.so
7f79761c6000-7f79761cf000 rw-p 00000000 00:00 0
7f79761dd000-7f79761e1000 rw-p 00000000 00:00 0
7f79761e1000-7f79761e2000 r--p 0001f000 fd:00 391164 /lib64/ld-2.12.so
7f79761e2000-7f79761e3000 rw-p 00020000 fd:00 391164 /lib64/ld-2.12.so
7f79761e3000-7f79761e4000 rw-p 00000000 00:00 0
7f79761e4000-7f797623c000 r-xp 00000000 fd:00 4301625 /home/svn/trunk/test
7f797643b000-7f797643f000 r--p 00057000 fd:00 4301625 /home/svn/trunk/test
7f797643f000-7f7976441000 rw-p 0005b000 fd:00 4301625 /home/svn/trunk/test
7f7977c9d000-7f7977d25000 rw-p 00000000 00:00 0 [heap]
7fffabf43000-7fffabf58000 rw-p 00000000 00:00 0 [stack]
7fffabfff000-7fffac000000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
通常会发生这种情况,当您意外删除由静态或全局对象拥有的对象时,将尝试在main()
完成后释放它。
更喜欢使用std::shared_ptr<>
或std::unique_ptr<>
,具体取决于拥有指针的所有权,以及非拥有指针的原始指针。然后你的代码中任何明确的delete
都是代码气味。 delete
需要一个原始指针,它只能是一个非拥有指针,所以代码的另一部分拥有这个对象,应该注意删除它。