Linux下内存泄露检测工具valgrind

2023-11-02

linux下有多种内存泄露的检测工具,valgrind算是比较好用的一款。valgrind功能比较强大,这里只是用到了内存泄露检测的功能。

一、从官网下载:http://www.valgrind.org/downloads/current.html

二、安装,先把下载的软件包拷贝到linux下目录,然后解压,按照下面顺序执行:

./autogen.sh      #执行脚本
./configure --prefix=/usr/local #指定安装目录
make  #编译
sudo make install   #安装,需要root权限

三、安装成功后可以通过valgrind --help命令查看该工具的使用方法。

四、如执行示例:

sudo valgrind --tool=memcheck --leak-check=full ./test_memcheck

 执行结果:

==29500== LEAK SUMMARY:
==29500==    definitely lost: 253 bytes in 3 blocks
==29500==    indirectly lost: 1,383 bytes in 9 blocks
==29500==      possibly lost: 272 bytes in 1 blocks
==29500==    still reachable: 97,140 bytes in 3,246 blocks
==29500==         suppressed: 0 bytes in 0 blocks
==29500== Reachable blocks (those to which a pointer was found) are not shown.
==29500== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==29500== 
==29500== For lists of detected and suppressed errors, rerun with: -s
==29500== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
//几种泄露问题类型
#definitely :内存丢失,需要尽快修复,解决问题
#indirectly :内存间接丢失,可能是由于definitely丢失造成的
#possibly :可能丢失的内存,应该也尽快修复问题
#still reachable :未释放但是可以访问的内存,应当修复问题
#suppressed :被系统自动修复的泄露问题

下面是 valgrind --help的用法:

usage: valgrind [options] prog-and-args

  tool-selection option, with default in [ ]:
    --tool=<name>             use the Valgrind tool named <name> [memcheck]

  basic user options for all Valgrind tools, with defaults in [ ]:
    -h --help                 show this message
    --help-debug              show this message, plus debugging options
    --version                 show version
    -q --quiet                run silently; only print error msgs
    -v --verbose              be more verbose -- show misc extra info
    --trace-children=no|yes   Valgrind-ise child processes (follow execve)? [no]
    --trace-children-skip=patt1,patt2,...    specifies a list of executables
                              that --trace-children=yes should not trace into
    --trace-children-skip-by-arg=patt1,patt2,...   same as --trace-children-skip=
                              but check the argv[] entries for children, rather
                              than the exe name, to make a follow/no-follow decision
    --child-silent-after-fork=no|yes omit child output between fork & exec? [no]
    --vgdb=no|yes|full        activate gdbserver? [yes]
                              full is slower but provides precise watchpoint/step
    --vgdb-error=<number>     invoke gdbserver after <number> errors [999999999]
                              to get started quickly, use --vgdb-error=0
                              and follow the on-screen directions
    --vgdb-stop-at=event1,event2,... invoke gdbserver for given events [none]
         where event is one of:
           startup exit valgrindabexit all none
    --track-fds=no|yes        track open file descriptors? [no]
    --time-stamp=no|yes       add timestamps to log messages? [no]
    --log-fd=<number>         log messages to file descriptor [2=stderr]
    --log-file=<file>         log messages to <file>
    --log-socket=ipaddr:port  log messages to socket ipaddr:port

  user options for Valgrind tools that report errors:
    --xml=yes                 emit error output in XML (some tools only)
    --xml-fd=<number>         XML output to file descriptor
    --xml-file=<file>         XML output to <file>
    --xml-socket=ipaddr:port  XML output to socket ipaddr:port
    --xml-user-comment=STR    copy STR verbatim into XML output
    --demangle=no|yes         automatically demangle C++ names? [yes]
    --num-callers=<number>    show <number> callers in stack traces [12]
    --error-limit=no|yes      stop showing new errors if too many? [yes]
    --exit-on-first-error=no|yes exit code on the first error found? [no]
    --error-exitcode=<number> exit code to return if errors found [0=disable]
    --error-markers=<begin>,<end> add lines with begin/end markers before/after
                              each error output in plain text mode [none]
    --show-error-list=no|yes  show detected errors list and
                              suppression counts at exit [no]
    -s                        same as --show-error-list=yes
    --keep-debuginfo=no|yes   Keep symbols etc for unloaded code [no]
                              This allows saved stack traces (e.g. memory leaks)
                              to include file/line info for code that has been
                              dlclose'd (or similar)
    --show-below-main=no|yes  continue stack traces below main() [no]
    --default-suppressions=yes|no
                              load default suppressions [yes]
    --suppressions=<filename> suppress errors described in <filename>
    --gen-suppressions=no|yes|all    print suppressions for errors? [no]
    --input-fd=<number>       file descriptor for input [0=stdin]
    --dsymutil=no|yes         run dsymutil on Mac OS X when helpful? [yes]
    --max-stackframe=<number> assume stack switch for SP changes larger
                              than <number> bytes [2000000]
    --main-stacksize=<number> set size of main thread's stack (in bytes)
                              [min(max(current 'ulimit' value,1MB),16MB)]

  user options for Valgrind tools that replace malloc:
    --alignment=<number>      set minimum alignment of heap allocations [16]
    --redzone-size=<number>   set minimum size of redzones added before/after
                              heap blocks (in bytes). [16]
    --xtree-memory=none|allocs|full   profile heap memory in an xtree [none]
                              and produces a report at the end of the execution
                              none: no profiling, allocs: current allocated
                              size/blocks, full: profile current and cumulative
                              allocated size/blocks and freed size/blocks.
    --xtree-memory-file=<file>   xtree memory report file [xtmemory.kcg.%p]

  uncommon user options for all Valgrind tools:
    --fullpath-after=         (with nothing after the '=')
                              show full source paths in call stacks
    --fullpath-after=string   like --fullpath-after=, but only show the
                              part of the path after 'string'.  Allows removal
                              of path prefixes.  Use this flag multiple times
                              to specify a set of prefixes to remove.
    --extra-debuginfo-path=path    absolute path to search for additional
                              debug symbols, in addition to existing default
                              well known search paths.
    --debuginfo-server=ipaddr:port    also query this server
                              (valgrind-di-server) for debug symbols
    --allow-mismatched-debuginfo=no|yes  [no]
                              for the above two flags only, accept debuginfo
                              objects that don't "match" the main object
    --smc-check=none|stack|all|all-non-file [all-non-file]
                              checks for self-modifying code: none, only for
                              code found in stacks, for all code, or for all
                              code except that from file-backed mappings
    --read-inline-info=yes|no read debug info about inlined function calls
                              and use it to do better stack traces.
                              [yes] on Linux/Android/Solaris for the tools
                              Memcheck/Massif/Helgrind/DRD only.
                              [no] for all other tools and platforms.
    --read-var-info=yes|no    read debug info on stack and global variables
                              and use it to print better error messages in
                              tools that make use of it (Memcheck, Helgrind,
                              DRD) [no]
    --vgdb-poll=<number>      gdbserver poll max every <number> basic blocks [5000] 
    --vgdb-shadow-registers=no|yes   let gdb see the shadow registers [no]
    --vgdb-prefix=<prefix>    prefix for vgdb FIFOs [/tmp/vgdb-pipe]
    --run-libc-freeres=no|yes free up glibc memory at exit on Linux? [yes]
    --run-cxx-freeres=no|yes  free up libstdc++ memory at exit on Linux
                              and Solaris? [yes]
    --sim-hints=hint1,hint2,...  activate unusual sim behaviours [none] 
         where hint is one of:
           lax-ioctls lax-doors fuse-compatible enable-outer
           no-inner-prefix no-nptl-pthread-stackcache fallback-llsc none
    --fair-sched=no|yes|try   schedule threads fairly on multicore systems [no]
    --kernel-variant=variant1,variant2,...
         handle non-standard kernel variants [none]
         where variant is one of:
           bproc android-no-hw-tls
           android-gpu-sgx5xx android-gpu-adreno3xx none
    --merge-recursive-frames=<number>  merge frames between identical
           program counters in max <number> frames) [0]
    --num-transtab-sectors=<number> size of translated code cache [32]
           more sectors may increase performance, but use more memory.
    --avg-transtab-entry-size=<number> avg size in bytes of a translated
           basic block [0, meaning use tool provided default]
    --aspace-minaddr=0xPP     avoid mapping memory below 0xPP [guessed]
    --valgrind-stacksize=<number> size of valgrind (host) thread's stack
                               (in bytes) [1048576]
    --show-emwarns=no|yes     show warnings about emulation limits? [no]
    --require-text-symbol=:sonamepattern:symbolpattern    abort run if the
                              stated shared object doesn't have the stated
                              text symbol.  Patterns can contain ? and *.
    --soname-synonyms=syn1=pattern1,syn2=pattern2,... synonym soname
              specify patterns for function wrapping or replacement.
              To use a non-libc malloc library that is
                  in the main exe:  --soname-synonyms=somalloc=NONE
                  in libxyzzy.so:   --soname-synonyms=somalloc=libxyzzy.so
    --sigill-diagnostics=yes|no  warn about illegal instructions? [yes]
    --unw-stack-scan-thresh=<number>   Enable stack-scan unwind if fewer
                  than <number> good frames found  [0, meaning "disabled"]
                  NOTE: stack scanning is only available on arm-linux.
    --unw-stack-scan-frames=<number>   Max number of frames that can be
                  recovered by stack scanning [5]
    --resync-filter=no|yes|verbose [yes on MacOS, no on other OSes]
              attempt to avoid expensive address-space-resync operations
    --max-threads=<number>    maximum number of threads that valgrind can
                              handle [500]

  user options for Memcheck:
    --leak-check=no|summary|full     search for memory leaks at exit?  [summary]
    --leak-resolution=low|med|high   differentiation of leak stack traces [high]
    --show-leak-kinds=kind1,kind2,.. which leak kinds to show?
                                            [definite,possible]
    --errors-for-leak-kinds=kind1,kind2,..  which leak kinds are errors?
                                            [definite,possible]
        where kind is one of:
          definite indirect possible reachable all none
    --leak-check-heuristics=heur1,heur2,... which heuristics to use for
        improving leak search false positive [all]
        where heur is one of:
          stdstring length64 newarray multipleinheritance all none
    --show-reachable=yes             same as --show-leak-kinds=all
    --show-reachable=no --show-possibly-lost=yes
                                     same as --show-leak-kinds=definite,possible
    --show-reachable=no --show-possibly-lost=no
                                     same as --show-leak-kinds=definite
    --xtree-leak=no|yes              output leak result in xtree format? [no]
    --xtree-leak-file=<file>         xtree leak report file [xtleak.kcg.%p]
    --undef-value-errors=no|yes      check for undefined value errors [yes]
    --track-origins=no|yes           show origins of undefined values? [no]
    --partial-loads-ok=no|yes        too hard to explain here; see manual [yes]
    --expensive-definedness-checks=no|auto|yes
                                     Use extra-precise definedness tracking [auto]
    --freelist-vol=<number>          volume of freed blocks queue     [20000000]
    --freelist-big-blocks=<number>   releases first blocks with size>= [1000000]
    --workaround-gcc296-bugs=no|yes  self explanatory [no].  Deprecated.
                                     Use --ignore-range-below-sp instead.
    --ignore-ranges=0xPP-0xQQ[,0xRR-0xSS]   assume given addresses are OK
    --ignore-range-below-sp=<number>-<number>  do not report errors for
                                     accesses at the given offsets below SP
    --malloc-fill=<hexnumber>        fill malloc'd areas with given value
    --free-fill=<hexnumber>          fill free'd areas with given value
    --keep-stacktraces=alloc|free|alloc-and-free|alloc-then-free|none
        stack trace(s) to keep for malloc'd/free'd areas       [alloc-and-free]
    --show-mismatched-frees=no|yes   show frees that don't match the allocator? [yes]

  Extra options read from ~/.valgrindrc, $VALGRIND_OPTS, ./.valgrindrc

  Memcheck is Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
  Valgrind is Copyright (C) 2000-2017, and GNU GPL'd, by Julian Seward et al.
  LibVEX is Copyright (C) 2004-2017, and GNU GPL'd, by OpenWorks LLP et al.

  Bug reports, feedback, admiration, abuse, etc, to: www.valgrind.org.

参考:

1、http://valgrind.org/

2、https://www.cnblogs.com/cnjy/p/4484951.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux下内存泄露检测工具valgrind 的相关文章

  • J-link烧录MCU镜像文件

    1 使用范围 本文档基于NXP M4芯片 介绍MCU镜像文件烧录流程以及在烧录过程中遇到的问题 2 烧录步骤2 1 资源准备 烧录前需准备MCU镜像文件 镜像文件一般由Keil工具 SylixOS IDE工具或者其他工具生成 本文档以Kei
  • docker:基本架构

    docker是典型的CS架构 包括客户端和服务端两大核心组件 同时通过镜像仓库来存储镜像 客户端和服务器既可以运行在同一个机器上 也可以通过socket或者RESTful API来进行通信 服务端 docker的服务端一般在宿主主机后台运行
  • VMware虚拟机网络设置(三种网络模式)

    VMware虚拟机网络设置 三种网络模式 VMware网络使用windows虚拟机客户端时一般默认NAT模式自动可以上网 近日安装macos时上网却不行 网上搜索后自己整理出来 对三种模式自己的看法 首先 找到编辑 gt 虚拟网络编辑器 虚
  • 工具:valgrind学习

    Valgrind手册 Quick start 文章目录 概述 体系结构 Valgrind 原理 安装 编译时需要注意 快速入门 LEAK SUMMARY 内存泄漏总结 分类 实践 第一个例子 没有内存泄漏 第二个例子 只申请内存而不释放 编
  • 使用ffmpeg转换webm格式到MP4格式

    1 cmd 2 切换到ffmpeg安装目录 cd C Program Files x86 Apowersoft Video Editor Pro 3 输入命令 ffmpeg i D djivideos 004 webm b v 2000k
  • 文件查重FindDupFile

    finddupfile是网上用的比较多的一款绿色查重软件 具体步骤请参考以下 1 下载软件 可从网上下载该软件 或者从以下地址进行下载 本软件从网上可自行下载 下载链接 https pan baidu com s 1KDJ9U4U 8HQa
  • Linux下内存泄露检测工具valgrind

    linux下有多种内存泄露的检测工具 valgrind算是比较好用的一款 valgrind功能比较强大 这里只是用到了内存泄露检测的功能 一 从官网下载 http www valgrind org downloads current htm
  • 记一次Swagger页面报错/error 404的排查过程

    记一次Swagger页面报错 error 404的排查过程 使用springfox swagger ui展示的页面如下 Maven引用 使用springfox swagger ui展示的页面如下 说是没有为 error这个路径指明确定的映射
  • office word 页码从任意页开始

    有时候在编写word文档的时候 页码会从封面就开始计算 想象一下如果你的论文封面突然蹦出一个页码 很难受有木有 解决这个问题很简单 网上教程很多 这里总结一下 1 找到你需要从零开始的页面 将这一页和上一页添加分节符 添加分节符1 添加分节
  • 绿色开源的屏幕/截屏OCR软件Capture2Text

    近日发现一个比较好的绿色开源的屏幕 截屏OCR软件 Capture2Text 官网说明 http capture2text sourceforge net 项目地址 https sourceforge net projects captur
  • 使用人声分离在线网站获得音乐

    有时候碰到一个广告中的音乐 觉得非常悦耳 想将它占为己有 使用到自己的片子中 但奈何其中有广告人声 想获得纯的音乐 如何做到呢 本文给出了方法 希望对你有用 注 本教程使用到了几个工具 1 fdm 下载片源 2 视频编辑大师 分离视频中的音
  • wireshark:界面介绍

    菜单栏 文件 打开文件集 保存包 导出HTTP对象 编辑 清除所有标记的包 忽略包和时间属性 视图 查看 隐藏工具栏和面板 编辑Time列 重设颜色 跳转 捕获 分析 创建显示过滤器宏 查看启用协议 保存关注解码 统计 创建图表并打开各种协
  • OD动调之脱壳:使用ESP定律寻找

    OD动调之脱壳 使用ESP定律寻找 using OD F8 sigle step Until stop Then data window follow Block then F9 Jmp gt oep 401171 You can unpa
  • git:分支管理策略

    主分支Master 首先 代码库应该有一个 而且仅有一个主分支 所有提供给用户使用的正式版本 都在这个主分支上发布 Git主分支的名字 默认叫做Master 它是自动建立的 版本库初始化以后 默认就是在主分支在进行开发 主分支 也是用于部署
  • Anaconda的使用

    1 anaconda介绍 Python虽然是一门优秀的程序语言 但其拥有出色的数据处理能力 尤其是在数据量巨大的时候 因而也吸引了不少数据分析人员的关注和使用 Python的数据处理能力主要依赖于NumPy SciPy Matplotlib
  • C#后端代码处理excel,按条件给单元格设置格式

    有时候在一些自定义场景下我们需要给excel表格打上标签格式 比如说财务想给每个月花费最高和最低员工打上标记 在输出表格时内容就已经处理完毕 准备工作 首先 下载Spire xls功能类库 点击这里下载 然后 在后端代码引入命名空间 usi
  • SourceInsight保存文件时自动去除多余的空格

    在用source insight 写代码后提交git 如果有一些多余的空格不删除就提交会出现标红的界面 在source insight 中可以设置保存时自动去除多余的空格 Options gt gt Files gt gt Remove e
  • 设置vim 永久显示行号

    在linux环境下 vim是常用的代码查看和编辑工具 在程序编译出错时 一般会提示出错的行号 但是用vim打开的代码确不显示行号 错误语句的定位非常不便 那么怎样才能让vim显示代码的行号呢 1 临时显示行号 如果只是临时显示vim的行号
  • 如何恢复华为手机中丢失的通讯录(使用时光机)

    1 登录 https cloud huawei com 2 如果忘记密码 可使用手机登录 1 手机中 华为帐号 2 扫描网页二维码 3 进入系统 3 点击 设置 4 点击 联系人时光机 5 选择需要还原的记录按 还原 6 打开通讯禄将还原的
  • PicGo安装与配置-Gitee图床

    PicGo安装与配置 Gitee图床 文章目录 PicGo安装与配置 Gitee图床 1 前言 2 下载 3 安装 4 Gitee 5 Node js 6 配置PicGo 6 1 PicGo界面配置 6 2 npm安装PicGo插件Gite

随机推荐

  • Warning:(23, 8) java: lombok.javac.apt.LombokProcessor could not be initialized.

    项目背景 开发工具idea springboot项目 在使用 Data时 启动项目后控制台报以下信息 Warning 23 8 java lombok javac apt LombokProcessor could not be initi
  • 闭关之 C++ 并发编程笔记(二):同步、内存模型和原子操作

    目录 第4章 并发操作的同步 4 1 等待事件或等待其他条件 4 1 1 凭借条件变量等待条件成立 4 1 2 利用条件变量构建线程安全的队列 4 2 使用future等待一次性事件发生 4 2 1 从后台任务返回值 4 2 2 关联fut
  • 定时删除某目录下几天前的文件

    系统每天生成日志 为了保证系统正常运行 需要不断清理系统空间 就把这种事情交给批处理文件来吧 这种方法简单实用 你只要通过任务计划和批处理文件就能实现 1 任务计划 进入 控制面板 任务计划 然后根据提示选择要运行的程序 运行时间即可 2
  • 基于STM32F103 实现按键状态机

    文章目录 开发板 开发环境 前言 按键消抖 按键硬件原理图 软件延时实现思路 实验目的 代码 按键状态 按键信息 按键相关定义 按键底层配置及状态获取 总结 开发板 正点原子STM32F103ZET6战舰 开发环境 stm32cubeMX
  • 单片机论文参考:1、基于单片机的电子琴

    摘要 随着社会的发展进步 音乐逐渐成为我们生活中很重要的一部分 有人曾说喜欢音乐的人不会向恶 我们都会抽空欣赏世界名曲 作为对精神的洗礼 本论文设计一个基于单片机的简易电子琴 电子琴是现代电子科技与音乐结合的产物 是一种新型的键盘乐器 它在
  • 遇到python调用selenium库使用chrome时候报错 selenium.common.exceptions.WebDriverException问题

    遇到selenium common exceptions WebDriverException问题 selenium common exceptions WebDriverException Message chromedriver exe
  • CTF中,命令中空格被过滤的解决方法

    转载于 作者 HyyMbb 链接 https blog csdn net a3320315 article details 99773192 来源 CSDN博客 1 linux cat flag txt cat IFS flag txt c
  • 【Matlab代码实现】电动过滤器:LPF和HPF、模拟调制:调幅和调频、WiFi、蓝牙和蜂窝网络的容量分析.....

    欢迎来到本博客 博主优势 博客内容尽量做到思维缜密 逻辑清晰 为了方便读者 座右铭 行百里者 半于九十 本文目录如下 目录 1 概述 2 运行结果 3 参考文献 4 Matlab代码实现 1 概述 为了更好 更深入地了解工程通信原理 需要获
  • 矢量图形绘制Illustrator 2022简体中文

    Illustrator 2022简称AI 是简体中文的版本 在矢量图形创作的行业是首选的软件 作为一个行业标准的AI 用途越来越多 比如产品的包装 书籍的插图插画设计 大街上随处可见的广告牌设计 社交媒体等的插图 越来越多的人使用AI进行创
  • 学习笔记(118):R语言入门基础-最年长和最年轻富豪

    立即学习 https edu csdn net course play 24913 285865 utm source blogtoedu na omit 显示非NA的数据
  • latex常见编译错误和细节

    1 nu sqrt mu等一些常用希腊字母和字符不能放在 text 里面 text sqrt text mu 是错误用法 2 使用左右尖括号 left langle和 right rangle 持续更新
  • 性能测试工具 Locust 分布式进行性能测试

    目录 前言 Options 介绍 前言 在进行性能测试时 我们需要确保应用程序在分布式环境下仍能正常运行 使用 Locust 进行性能测试时 当一台单机不足以模拟所需的用户数量的时候 可以在多台机器上分布式的执行性能测试 首先 需要在主机下
  • 认识kubenetes的核心组件之一kubelet

    kubelet是在每个 Node 节点 包括master节点 上运行的主要 节点代理 默认监听10250端口 kubelet主要完成如下一些任务 接收并执行master发送来的指令 管理pod以及pod中的容器 管理节点和更新节点状态信息
  • Detr源码解读(mmdetection)

    Detr源码解读 mmdetection 1 原理简要介绍 整体流程 在给定一张输入图像后 1 特征向量提取 首先经过ResNet提取图像的最后一层特征图F 注意此处仅仅用了一层特征图 是因为后续计算复杂度原因 另外 由于仅用最后一层特征图
  • sql转nosql的第一件事:能不能实现复杂计算逻辑——MongoDB

    公司开始要把部分业务转到NoSQL上 并且决定开始使用mongodb作为技术栈 于是花了两天时间搭建服务 学习语法 以下给大家分享一些关系型数据库sqlserver在非关系型数据库mongodb的一些复杂语句的实现 首先 假设我们有一张表
  • golang基于errgroup实现并发调用

    文章目录 串行调用 基于sync WaitGroup实现简单的并发调用 基于errgroup Group实现并发调用 总结 串行调用 在用go编写web rpc服务器的时候 经常会出现需要对下游多 个 组 服务调用rpc 或者其他比较耗时的
  • nltk 安装教程

    windows10环境下 安装 ntlk book 教程 下载nltk 和nltk data 下载完整nltk项目安装包地址 https github com nltk nltk data nltk book压缩包下载地址 https jh
  • 久久未至的Codevs1024一塔湖图解题报告

    一直想给这个题写个解题报告但是给忘了OTZ难产了这么久终于出来了 这个题当时坑了我一个星期整 所以一定要写一个解题报告纪念一下 1024 一塔湖图 时间限制 1 s 空间限制 128000 KB 题目等级 黄金 Gold Pending 总
  • ChainDesk-基于区块链技术实现的学历信息征信系统-需求分析

    作者 ChainDesk韩小东 13 1 1 需求分析 现在是一个信息化的高科技时代 许许多多的企业必须紧跟时代步伐 不断创新 才能发展壮大 而企业的发展必然离不开人才队伍的建设 也可以说创新是企业发展的动力 而人才却是企业发展的根本 所以
  • Linux下内存泄露检测工具valgrind

    linux下有多种内存泄露的检测工具 valgrind算是比较好用的一款 valgrind功能比较强大 这里只是用到了内存泄露检测的功能 一 从官网下载 http www valgrind org downloads current htm