首页 > 解决方案 > Valgrind 不显示任何信息(因为 exec 调用?)

问题描述

我正在使用 valgrind 检查学校项目的内存泄漏。问题是 valgrind 只显示前几行通常的演示文稿,但没有给我任何有关泄漏和错误的信息:

==4734== Memcheck, a memory error detector
==4734== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4734== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==4734== Command: ./pipex test_infile grep\ test wc\ -l test_outfile
==4734== 

当我不带任何参数运行程序时,它会正确显示信息:

==4626== Memcheck, a memory error detector
==4626== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4626== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==4626== Command: ./pipex
==4626== 
ERROR
==4626== 
==4626== HEAP SUMMARY:
==4626==     in use at exit: 0 bytes in 0 blocks
==4626==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==4626== 
==4626== All heap blocks were freed -- no leaks are possible
==4626== 
==4626== For lists of detected and suppressed errors, rerun with: -s
==4626== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

也许是因为我的程序使用了 forks、pipes 和 exec 调用。该程序(pipex)的目标是做到这一点:

./pipex infile cmd1 cmd2 outfile必须等同于 bash< infile cmd1 | cmd 2 > outfile

关于为什么会发生这种情况以及如何检查错误和泄漏的任何提示?

标签: cpipeforkexecvalgrind

解决方案


推荐阅读