0

这是一个项目的 valgrind 输出:

==2433== Invalid free() / delete / delete[] / realloc()
==2433==    at 0x402B06C: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2433==    by 0x43F345B: av_freep (mem.c:172)
==2433==    by 0x5A6F4D2: (below main) (libc-start.c:226)
==2433==  Address 0xb3fd830 is 48 bytes inside a block of size 111,634 alloc'd
==2433==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2433==    by 0x80BB6B5: _talloc_realloc (talloc.c:997)

Address与以 开头的行相比,以 开头的行缩进一个空格Invalid。这是否意味着一个导致另一个?或者他们是分开的?

如果是分开的,by 0x5A6F4D2: (below main) (libc-start.c:226)从哪里来?我觉得(below main)这与它有关,但我在硬盘驱动器上的任何地方都找不到 libc-start.c。

4

2 回答 2

2

是的,它为您提供有关无效免费的更多详细信息。前四行描述了无效调用(在本例中为 free)和 free 时的调用堆栈。以下三行提供了额外的数据。在这种情况下,valgrind 识别出传递给的地址free包含在分配的区域内,并提供偏移量、块的大小和该分配的调用堆栈。

于 2012-06-15T16:50:05.597 回答
1

根据valgrind.org,层次结构应该是扁平的,如下所示:

==3016== Invalid write of size 1
==3016==    at 0x80484DA: main (in /jfs/article/sample2)
==3016==    by 0x40271507: __libc_start_main (../sysdeps/generic/libc-start.c:129)
==3016==    by 0x80483B1: free@@GLIBC_2.0 (in /jfs/article/sample2)
==3016==    Address 0x40CA0224 is 0 bytes after a block of size 512 alloc'd
==3016==    at 0x400483E4: malloc (vg_clientfuncs.c:100)
==3016==    by 0x80484AA: main (in /jfs/article/sample2)
==3016==    by 0x40271507: __libc_start_main (../sysdeps/generic/libc-start.c:129)
==3016==    by 0x80483B1: free@@GLIBC_2.0 (in /jfs/article/sample2)

我会将Address您的输出中的缩进视为上述内容,因为它可能是特定于版本的更改,以使输出更具可读性。

于 2012-06-15T16:49:44.287 回答