首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >华润报告了太多的错误

华润报告了太多的错误
EN

Stack Overflow用户
提问于 2015-04-07 15:23:28
回答 1查看 484关注 0票数 4

请考虑以下代码:

代码语言:javascript
复制
int main(int argc, char const *argv[])
{
    char *string = NULL;
    string = malloc(sizeof(char) * 30);
    free(string);
    return 0;
}

我删除了一个char指针,然后释放它。现在考虑一下val砂糖的输出:

代码语言:javascript
复制
==58317== Memcheck, a memory error detector
==58317== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==58317== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==58317== Command: ./a.out
==58317== 
==58317== 
==58317== HEAP SUMMARY:
==58317==     in use at exit: 34,941 bytes in 424 blocks
==58317==   total heap usage: 505 allocs, 81 frees, 41,099 bytes allocated
==58317== 
==58317== LEAK SUMMARY:
==58317==    definitely lost: 0 bytes in 0 blocks
==58317==    indirectly lost: 0 bytes in 0 blocks
==58317==      possibly lost: 0 bytes in 0 blocks
==58317==    still reachable: 0 bytes in 0 blocks
==58317==         suppressed: 34,941 bytes in 424 blocks
==58317== 
==58317== For counts of detected and suppressed errors, rerun with: -v
==58317== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

怎么可能有那么多的错误和自由呢?

编辑:这就是我在使用valgrind --leak-check=yes --gen-suppressions=all ./a.out运行时得到的结果,我正在尝试创建一个supp文件。

代码语言:javascript
复制
==60943== Memcheck, a memory error detector
==60943== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==60943== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==60943== Command: ./a.out
==60943== 
==60943== 
==60943== HEAP SUMMARY:
==60943==     in use at exit: 34,941 bytes in 424 blocks
==60943==   total heap usage: 505 allocs, 81 frees, 41,099 bytes allocated
==60943== 
==60943== LEAK SUMMARY:
==60943==    definitely lost: 0 bytes in 0 blocks
==60943==    indirectly lost: 0 bytes in 0 blocks
==60943==      possibly lost: 0 bytes in 0 blocks
==60943==    still reachable: 0 bytes in 0 blocks
==60943==         suppressed: 34,941 bytes in 424 blocks
==60943== 
==60943== For counts of detected and suppressed errors, rerun with: -v
==60943== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 15)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-07 15:46:33

这些块是由链接到您的可执行文件的系统库分配的(其中一些块也被释放了)。

Valgrind有一个默认的suppression文件来抑制系统库中的泄漏,这就是您可以在输出中看到的内容:

代码语言:javascript
复制
==58317==         suppressed: 34,941 bytes in 424 blocks

如果您想要更多关于究竟被禁止的内容的详细信息,可以使用-v选项。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29495225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档