0

我的程序 (./a.out) 遇到了分段错误,因此我使用 Valgrind 检查是否可以找到程序损坏的代码行。我得到了以下输出,但我无法理解它们。对我来说,输出中最可疑的行是==17967== Address 0x20687cf80 is 0 bytes inside a block of size 16 alloc'd,这行是否意味着地址 0x20687cf80 没有正确分配内存块?我能做些什么来解决这个问题。

我正在使用具有 64GB 内存的 64 位 linux。

[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]#
4

1 回答 1

3

“可疑”输出==17967== 地址 0x20687cf80 在大小为 16 的块内分配了 0 个字节,这意味着有一个已分配的内存块,大小为 16 个字节。地址 0x20687cf80 是该块的第一个字节的地址(即,它是整个块的地址)。因此,该行本身只会告诉您有关整个警告中涉及的内存块的详细信息。

警告本身是关于“不匹配的 free()”。以下几行显示了free调用的位置:

==17967== 在 0x4A055FE: 空闲 (vg_replace_malloc.c:366)
==17967== 在 0x401B13: hash_table_delete(BloomFilter*, char*) (BloomFilterAndHashTable.cpp:503)

意思是,hash_table_delete打电话free()。现在,为什么 valgrind 认为这是不匹配的?因为被释放的内存块的地址(0x20687cf80)是由分配的operator new,它被调用hash_table_insert

==17967== 在 0x4A05F97:操作员新(无符号长)(vg_replace_malloc.c:261)
==17967== 通过 0x40146D:hash_table_insert(char*,int,BloomFilter*)(BloomFilterAndHashTable.cpp:293)

这是可疑的。如果它是您的错误的根源是另一个问题,但无论如何您都应该修复它。

于 2013-04-25T11:52:06.877 回答