我在ARM平台上使用Valgrind 3.19.0版本。我写了一个小程序,有一个内存泄漏;来源如下:
#include <stdlib.h>
int main()
{
char* p = (char*)malloc(1024 * 1024);
return 0;
}
我把它和
arm-buildroot-linux-gnueabi-gcc -g -O0 -o test test.c
然后在我的ARM机器上运行Valgrind:
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose ./test
看起来像Valgrind成功地检测到泄漏,但它没有提供有关源代码的信息。下面是输出:
==1221== Memcheck, a memory error detector
==1221== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==1221== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==1221== Command: ./test
==1221==
==1221==
==1221== HEAP SUMMARY:
==1221== in use at exit: 1,048,576 bytes in 1 blocks
==1221== total heap usage: 2 allocs, 1 frees, 1,068,800 bytes allocated
==1221==
==1221== 1,048,576 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1221== at 0x4864DE4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-arm-linux.so)
==1221==
==1221== LEAK SUMMARY:
==1221== definitely lost: 1,048,576 bytes in 1 blocks
==1221== indirectly lost: 0 bytes in 0 blocks
==1221== possibly lost: 0 bytes in 0 blocks
==1221== still reachable: 0 bytes in 0 blocks
==1221== suppressed: 0 bytes in 0 blocks
==1221==
==1221== For lists of detected and suppressed errors, rerun with: -s
==1221== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
是否有可能获得分配内存的源代码行?如果是,我错在哪里?
1条答案
按热度按时间hgc7kmma1#
感谢phd的评论,我下载了最新版本的Valgrind,用我的工具链交叉编译并复制到我的目标机器上。较新的版本正确显示源代码行,其中泄漏的内存已被分配