加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Valgrind在不终止程序的情况下检测内存泄漏

发布时间:2020-12-16 07:07:08 所属栏目:百科 来源:网络整理
导读:Valgrind是否有可能在不终止程序的情况下检测可达/内存泄漏? 也就是说,如何在退出程序之前知道结果? 解决方法 如果你在GDB下运行程序,那么文档中描述了一些选项,特别是 MemCheck Monitor Commands部分,具体来说,提到的命令之一是leak_check: leak_check [
Valgrind是否有可能在不终止程序的情况下检测可达/内存泄漏?

也就是说,如何在退出程序之前知道结果?

解决方法

如果你在GDB下运行程序,那么文档中描述了一些选项,特别是 MemCheck Monitor Commands部分,具体来说,提到的命令之一是leak_check:

  • leak_check [full*|summary] [kinds <set>|reachable|possibleleak*|definiteleak] [heuristics heur1,heur2,...] [increased*|changed|any] [unlimited*|limited <max_loss_records_output>] performs a leak check. The * in the arguments indicates the default values.

If the [full*|summary] argument is summary,only a summary of the leak search is given; otherwise a full leak report is produced. A full leak report gives detailed information for each leak: the stack trace where the leaked blocks were allocated,the number of blocks leaked and their total size. When a full report is requested,the next two arguments further specify what kind of leaks to report. A leak’s details are shown if they match both the second and third argument. A full leak report might output detailed information for many leaks. The nr of leaks for which information is output can be controlled using the limited argument followed by the maximum nr of leak records to output. If this maximum is reached,the leak search outputs the records with the biggest number of bytes.

The kinds argument controls what kind of blocks are shown for a full leak search. The set of leak kinds to show can be specified using a <set> similarly to the command line option --show-leak-kinds. Alternatively,the value definiteleak is equivalent to kinds definite,the value possibleleak is equivalent to kinds definite,possible : it will also show possibly leaked blocks,.i.e those for which only an interior pointer was found. The value reachable will show all block categories (i.e. is equivalent to kinds all).

The heuristics argument controls the heuristics used during the leak search. The set of heuristics to use can be specified using a <set> similarly to the command line option --leak-check-heuristics. The default value for the heuristics argument is heuristics none.

The [increased*|changed|any] argument controls what kinds of changes are shown for a full leak search. The value increased specifies that only block allocation stacks with an increased number of leaked bytes or blocks since the previous leak check should be shown. The value changed specifies that allocation stacks with any change since the previous leak check should be shown. The value any specifies that all leak entries should be shown,regardless of any increase or decrease. When If increased or changed are specified,the leak report entries will show the delta relative to the previous leak report.

等等.

如果你想在程序控制下进行,那么下一节Client Requests描述了C程序可以进行的API调用.这些包括:

  • VALGRIND_DO_LEAK_CHECK: does a full memory leak check (like --leak-check=full) right now. This is useful for incrementally checking for leaks between arbitrary places in the program’s execution. It has no return value.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读