为什么valgrind的堆栈跟踪分为两部分?

时间:2015-08-25 19:43:33

标签: c valgrind

the docs中,解释了Valgrind的Memcheck错误报告, 4.2.1节中有一个这样的例子。非法读取/非法写入错误

Invalid read of size 4
   at 0x40F6BBCC: (within /usr/lib/libpng.so.2.1.0.9)
   by 0x40F6B804: (within /usr/lib/libpng.so.2.1.0.9)
   by 0x40B07FF4: read_png_image(QImageIO *) (kernel/qpngio.cpp:326)
   by 0x40AC751B: QImageIO::read() (kernel/qimage.cpp:3621)
 Address 0xBFFFF0E0 is not stack'd, malloc'd or free'd

以下是我的例子:

==20285== Invalid read of size 8
==20285==    at 0x401E8C: arraylist_get (arraylist.c:68)
==20285==    by 0x401254: test_arraylist_remove (test_arraylist.c:68)
==20285==    by 0x401366: main (tests.c:31)
==20285==  Address 0x59d65f0 is 0 bytes inside a block of size 2 alloc'd
==20285==    at 0x4C2CE8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20285==    by 0x402302: pool_realloc (pool.c:57)
==20285==    by 0x401D97: arraylist_remove (arraylist.c:53)
==20285==    by 0x401243: test_arraylist_remove (test_arraylist.c:67)
==20285==    by 0x401366: main (tests.c:31)

注意 - 在我的情况下,在Address 0x59d65f0 is 0 bytes inside a block of size 2 alloc'd之后有一个延续 - 此错误中有另一个堆栈跟踪。这是什么意思?

PS
完整的Valgrind输出:
https://gist.github.com/AndrewPashkin/b1b1b484153642b1ae14

1 个答案:

答案 0 :(得分:1)

这是两个独立的堆栈跟踪。

首先,描述无效访问,其中包含代码的堆栈跟踪:

==20285== Invalid read of size 8
==20285==    at 0x401E8C: arraylist_get (arraylist.c:68)
==20285==    by 0x401254: test_arraylist_remove (test_arraylist.c:68)
==20285==    by 0x401366: main (tests.c:31)

其次,对正在访问的内存的描述,以及分配它的代码的堆栈跟踪:

==20285==  Address 0x59d65f0 is 0 bytes inside a block of size 2 alloc'd
==20285==    at 0x4C2CE8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20285==    by 0x402302: pool_realloc (pool.c:57)
==20285==    by 0x401D97: arraylist_remove (arraylist.c:53)
==20285==    by 0x401243: test_arraylist_remove (test_arraylist.c:67)
==20285==    by 0x401366: main (tests.c:31)