英文:
Valgrind not giving source code line for memory leak
问题
I am using Valgrind, version 3.19.0 on an ARM platform.
我正在使用Valgrind,版本3.19.0,在ARM平台上。
I wrote a small program that has a memory leak; here's the source:
我写了一个有内存泄漏的小程序;以下是源代码:
#include <stdlib.h>
int main()
{
char* p = (char*)malloc(1024 * 1024);
return 0;
}
I compiled it with:
我使用以下命令编译它:
arm-buildroot-linux-gnueabi-gcc -g -O0 -o test test.c
Then run with Valgrind on my ARM machine:
然后在我的ARM机器上使用Valgrind运行:
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose ./test
Looks like Valgrind successfully detects the leak, but it gives no info about the source code. Here's the output:
看起来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 block
==1221== total heap usage: 2 allocs, 1 frees, 1,068,800 bytes allocated
==1221==
==1221== 1,048,576 bytes in 1 block 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 block
==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)
Is it possible to get the source code line where the memory was allocated? If yes, where am I wrong?
是否有可能获取分配内存的源代码行?如果可以,我错在哪里?
英文:
I am using Valgrind, version 3.19.0 on an ARM platform.
I wrote a small program that hase a memory leak; here's the source:
#include <stdlib.h>
int main()
{
char* p = (char*)malloc(1024 * 1024);
return 0;
}
I compiled it with
> ```sh
> arm-buildroot-linux-gnueabi-gcc -g -O0 -o test test.c
Then run with Valgrind on my ARM machine:
> ```sh
> valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose ./test
Looks like Valgrind successfully detect the leak, bu it gives no info about the source code. Here's the output:
==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)
Is it possible to get the source code line where the memory was allocated? If yes, where am I wrong?
答案1
得分: 1
感谢phd的评论,我下载了Valgrind的最新版本,使用我的工具链进行了交叉编译,并将其复制到了我的目标机器上。新版本可以正确显示分配泄漏内存的源代码行。
英文:
Thanks to phd comment, I download the latest version of Valgrind, cross compiled it with my toolchain and copied it to my target machine. The newer version properly display the source code line where the leaked memory has been allocated
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论