我有一个采用各种命令行参数的C程序,即
./Coupled arg1 argv2
当我使用valgrind作为
运行时valgrind ./Coupled arg1 arg2
我没有内存泄漏。但是,当我使用名为run
的形式的bash脚本
arg1=thing1
arg2=thing2
./Coupled $thing1 $thing2
然后运行
valgrind ./run
我仍然遇到很多内存泄漏。我读过,仍然可以达到的内存泄漏不是一个大问题,但是我很想知道为什么会这样?当运行带有--leak-check=full --show-leak-kinds=all
标志的valgrind时,将显示示例输出(完整的valgrind输出为多页)
==4518== 1 bytes in 1 blocks are still reachable in loss record 1 of 269
==4518== at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==4518== by 0x46A3DA: xmalloc (in /usr/bin/bash)
==4518== by 0x437219: make_variable_value (in /usr/bin/bash)
==4518== by 0x438230: ??? (in /usr/bin/bash)
==4518== by 0x43A35E: initialize_shell_variables (in /usr/bin/bash)
==4518== by 0x41DD92: ??? (in /usr/bin/bash)
==4518== by 0x41C482: main (in /usr/bin/bash)
答案 0 :(得分:5)
valgrind ./run
将调试 shell 而不是您的程序。
看看输出,看看它如何提及(例如)
== 4518 ==通过0x41C482:main(在/ usr / bin / bash 中)
[重点突出]
如果要调试程序,则需要在脚本中运行valgrind
:
arg1=thing1
arg2=thing2
valgrind ./Coupled $thing1 $thing2