这是 Valgring 报告:
==14546== Thread 5:
==14546== Invalid free() / delete / delete[]
==14546== at 0x490555D: free (vg_replace_malloc.c:235)
==14546== by 0x3BF7EFAA8F: free_mem (in /lib64/tls/libc-2.3.4.so)
==14546== by 0x3BF7EFA581: __libc_freeres (in /lib64/tls/libc-2.3.4.so)
==14546== by 0x4802676: _vgw_freeres (vg_preloaded.c:62)
==14546== Address 0x4DC4EE0 is not stack'd, malloc'd or (recently) free'd
我怎么知道它是哪个线程,因为线程号因一次执行而异?威尔assigning names to my threads在这里帮忙?
编辑:我认为不会,因为手册的 DRD 部分中提到了这一点。
我在 Red Hat Enterprise Linux AS4 上使用 valgrind-3.1.1。
最佳答案
您可能正在释放一个全局变量(地址:0x4DC4EE0
非常接近 Linux/x86_64 上默认情况下全局变量所在的位置)。
在 GDB 下运行程序,然后执行 info symbol 0x4DC4EE0
,GDB 应该会告诉您所有您需要知道的信息。
更新:
Valgrind 3.6 实际上已经报告了全局符号。例如,给定这个错误程序:
#include <stdlib.h>
int x;
int main()
{
free(&x);
return 0;
}
Valgrind 3.6 报告:
==18731== Invalid free() / delete / delete[]
==18731== at 0x4C240E8: free /tmp/vg/coregrind/m_replacemalloc/vg_replace_malloc.c:394
==18731== by 0x4004AA: main /home/t.c:7
==18731== Address 0x60089c is 0 bytes inside data symbol "x"
关于c++ - 如何在多线程程序中定位 Valgrind 报告的 free/delete 不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3872290/