Valgrind 未检测:“总堆使用量:0 次分配、0 次释放、0 字节分配”

发布于 2024-12-16 23:58:13 字数 1758 浏览 0 评论 0原文

即使在引入故意内存泄漏之后,valgrind 也会显示:

==13483== HEAP SUMMARY:
==13483==     in use at exit: 0 bytes in 0 blocks
==13483==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==13483== 
==13483== All heap blocks were freed -- no leaks are possible

可执行文件是用 G++ 4.1.2 和 4.6.2 编译的:

g++ -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g -pthread -Wno-long-long -Wno-uninitialized <snipped definitions and include directives from the build system>

我尝试过使用 Valgrind 3.5.0 和 3.6.1,例如:

valgrind --leak-check=full --undef-value-errors=no --show-reachable=yes <executable args>

在我正在工作的库的框架内上,我正在使用一个简单的测试用例:

#include "pwiz/utility/misc/Std.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "pwiz/data/identdata/IdentDataFile.hpp"

using namespace pwiz::cv;
using namespace pwiz::data;
using namespace pwiz::identdata;
using namespace pwiz::util;

int main(int argc, char** argv)
{
    vector<string> args(argv+1, argv+argc);
    BOOST_FOREACH(const bfs::path& filename, args)
    {
        // intentional memory leak
        IdentDataFile* idp = new IdentDataFile(filename.string());
        IdentDataFile& id = *idp;
        cout << filename.string() << " "
             << id.analysisCollection.spectrumIdentification[0]->activityDate << " "
             << id.analysisCollection.spectrumIdentification[0]->spectrumIdentificationListPtr->spectrumIdentificationResult.size()
             << "\n";
    }
    return 0;
}

显然我不希望其他人能够编译这个,但无论如何我怀疑它是关于库的一些东西导致了 valgrind 所以更简单的测试用例是没有意义的。我知道 for 循环正在执行,因为我在 Valgrind 执行期间得到了 cout 输出。如何在不进一步简化的情况下调试它?

Even after introducing an intentional memory leak valgrind shows:

==13483== HEAP SUMMARY:
==13483==     in use at exit: 0 bytes in 0 blocks
==13483==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==13483== 
==13483== All heap blocks were freed -- no leaks are possible

The executable was compiled with G++ 4.1.2 and 4.6.2 with:

g++ -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g -pthread -Wno-long-long -Wno-uninitialized <snipped definitions and include directives from the build system>

I've tried with Valgrind 3.5.0 and 3.6.1 like:

valgrind --leak-check=full --undef-value-errors=no --show-reachable=yes <executable args>

Within the framework of the library I'm working on, I'm using a simple test case:

#include "pwiz/utility/misc/Std.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "pwiz/data/identdata/IdentDataFile.hpp"

using namespace pwiz::cv;
using namespace pwiz::data;
using namespace pwiz::identdata;
using namespace pwiz::util;

int main(int argc, char** argv)
{
    vector<string> args(argv+1, argv+argc);
    BOOST_FOREACH(const bfs::path& filename, args)
    {
        // intentional memory leak
        IdentDataFile* idp = new IdentDataFile(filename.string());
        IdentDataFile& id = *idp;
        cout << filename.string() << " "
             << id.analysisCollection.spectrumIdentification[0]->activityDate << " "
             << id.analysisCollection.spectrumIdentification[0]->spectrumIdentificationListPtr->spectrumIdentificationResult.size()
             << "\n";
    }
    return 0;
}

Obviously I don't expect others to be able to compile this, but anyway I suspect it's something about the library that's tripping up valgrind so a simpler test case would be pointless. And I know that the for loop is being executed because I get the cout output during Valgrind execution. How can I debug it without simplifying further?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北陌 2024-12-23 23:58:13

它实际上归结为链接器选项。我使用 -static 进行编译,因此 valgrind 没有机会替换它自己的 malloc 实现。不幸的是 valgrind 至少没有警告这一点!

It boiled down to the linker options actually. I was compiling with -static, so valgrind did not have a chance to substitute its own malloc implementation. Unfortunate that valgrind doesn't at least warn about this though!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文