Dan*_*elJ -2 c bash memory-leaks
我有一个C程序,它采用各种命令行参数,即
./Coupled arg1 argv2
Run Code Online (Sandbox Code Playgroud)
当我和valgrind一起运行时
valgrind ./Coupled arg1 arg2
Run Code Online (Sandbox Code Playgroud)
我没有内存泄漏.但是当我使用bash脚本,叫run形式,
arg1=thing1
arg2=thing2
./Coupled $thing1 $thing2
Run Code Online (Sandbox Code Playgroud)
然后跑
valgrind ./run
Run Code Online (Sandbox Code Playgroud)
我得到了很多仍然可以访问的内存泄漏.我已经读过,仍然可以访问内存泄漏不是一个大问题,但我很想知道为什么会发生这种情况?当用--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)
Run Code Online (Sandbox Code Playgroud)
valgrind ./run将调试shell而不是您的程序.
看一下输出,看看它是如何提到的(例如)
== 4518 == by 0x41C482:main(在/ usr/bin/bash中)
[强调我的]
如果要调试程序,则需要valgrind 在脚本中运行:
arg1=thing1
arg2=thing2
valgrind ./Coupled $thing1 $thing2
Run Code Online (Sandbox Code Playgroud)