我的程序(./a.out)遇到了分段错误,因此我使用Valgrind检查是否可以找到程序损坏的代码行。我得到了以下输出,但我无法理解它们。对我来说,输出中最可疑的行是 == 17967 ==地址0x20687cf80是一个大小为16的块中的0字节allocned ,这行是否意味着地址0x20687cf80不是按比例分配的记忆块?我该怎么做才能解决这个问题。
我正在使用64位linux和64GB内存。
[root@gpu BloomFilterAndHashTable]# valgrind --tool=memcheck --leak-check=full ./a.out /mnt/disk2/experiments/two_stage_bloom_filter/test/10_10.txt /mnt/disk2/experiments/10M_worstcase_trace/w_10_10.trace 24
==17967== Memcheck, a memory error detector
==17967== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==17967== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==17967== Command: ./a.out /mnt/disk2/experiments/two_stage_bloom_filter/test/10_10.txt /mnt/disk2/experiments/10M_worstcase_trace/w_10_10.trace 24
==17967==
9998797 Prefixes loaded! //output of my program
==17967== Warning: set address range perms: large range [0x4201a040, 0x6f423220) (defined)
==17967== Warning: set address range perms: large range [0x9c834040, 0x20687cf40) (undefined)
insertion cost time(us): 173168519 9998797 17.318935 0.057740 //output of my program
==17967== Warning: set address range perms: large range [0x23647d040, 0x25647d040) (defined)
Trace loaded! //output of my program
lookup cost time(us): 5728767367 67108864 85.365286 0.011714 //output of my program
==17967== Mismatched free() / delete / delete []
==17967== at 0x4A055FE: free (vg_replace_malloc.c:366)
==17967== by 0x401B13: hash_table_delete(BloomFilter*, char*) (BloomFilterAndHashTable.cpp:503)
==17967== by 0x402212: main (BloomFilterAndHashTable.cpp:687)
==17967== Address 0x20687cf80 is 0 bytes inside a block of size 16 alloc'd
==17967== at 0x4A05F97: operator new(unsigned long) (vg_replace_malloc.c:261)
==17967== by 0x40146D: hash_table_insert(char*, int, BloomFilter*) (BloomFilterAndHashTable.cpp:293)
==17967== by 0x401DD5: main (BloomFilterAndHashTable.cpp:597)
==17967==
Delete succeeded! //output of my program
deletion cost time(us): 178048113 9998797 17.806953 0.056158 //output of my program
==17967== Warning: set address range perms: large range [0x23647d030, 0x25647d050) (noaccess)
--17967:0:aspacem Valgrind: FATAL: VG_N_SEGMENTS is too low.
--17967:0:aspacem Increase it and rebuild. Exiting now.
[root@gpu BloomFilterAndHashTable]#
答案 0 :(得分:2)
“可疑”输出 == 17967 ==地址0x20687cf80是大小为16的块内的0字节alloc'd 表示存在已分配的内存块,大小为16字节。地址0x20687cf80是该块的第一个字节的地址(即它是整个块的地址)。因此,该行本身只会告诉您有关整个警告中涉及的内存块的详细信息。
警告本身是关于“不匹配的免费()”。以下行显示调用free
的位置:
== 17967 ==在0x4A055FE:free(vg_replace_malloc.c:366)
== 17967 == by 0x401B13:hash_table_delete(BloomFilter *,char *)(BloomFilterAndHashTable.cpp:503)
含义,hash_table_delete
调用free()
。现在,为什么valgrind认为这是不匹配的?因为被释放的内存块的地址(0x20687cf80)是由operator new
分配的hash_table_insert
分配的:
== 17967 == at 0x4A05F97:operator new(unsigned long)(vg_replace_malloc.c:261)
== 17967 == by 0x40146D:hash_table_insert(char *,int,BloomFilter *)(BloomFilterAndHashTable.cpp:293)
这是可疑的。如果它是您的错误的来源是另一个问题,但无论如何您应该修复它。