首页 > 系统相关 >一个查看堆内存泄露的工具

一个查看堆内存泄露的工具

时间:2022-09-26 18:11:13浏览次数:60  
标签:11 blocks lost 查看 4642 bytes 40 内存 泄露

valgrind

 1 #include <stdlib.h>
 2 #include <stdio.h>
 3 
 4 void f(void)
 5 {
 6     int *x = malloc(10 * sizeof(int));
 7     x[10] = 0;
 8 }
 9 int main(void)
10 {
11     f();
12     return 0;
13 }
测试代码

控制台:

 

 

==4642== Memcheck, a memory error detector
==4642== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4642== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==4642== Command: ./a
==4642==
==4642== Invalid write of size 4
==4642== at 0x10916B: f (a.c:7)
==4642== by 0x109180: main (a.c:11)
==4642== Address 0x4a50068 is 0 bytes after a block of size 40 alloc'd
==4642== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==4642== by 0x10915E: f (a.c:6)
==4642== by 0x109180: main (a.c:11)
==4642==
==4642==
==4642== HEAP SUMMARY:
==4642== in use at exit: 40 bytes in 1 blocks
==4642== total heap usage: 1 allocs, 0 frees, 40 bytes allocated
==4642==
==4642== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==4642== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==4642== by 0x10915E: f (a.c:6)
==4642== by 0x109180: main (a.c:11)
==4642==
==4642== LEAK SUMMARY:
==4642== definitely lost: 40 bytes in 1 blocks
==4642== indirectly lost: 0 bytes in 0 blocks
==4642== possibly lost: 0 bytes in 0 blocks
==4642== still reachable: 0 bytes in 0 blocks
==4642== suppressed: 0 bytes in 0 blocks
==4642==
==4642== For lists of detected and suppressed errors, rerun with: -s
==4642== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

标签:11,blocks,lost,查看,4642,bytes,40,内存,泄露
From: https://www.cnblogs.com/xingming/p/16731878.html

相关文章

  • 大页内存(Huge Pages)
    简单来说就是通过增大操作系统页的大小来减小页表,从而避免快表缺失。在介绍之前需要强调一点,大页内存也有适用范围,程序耗费内存很小或者程序的访存局部性很好,大页内存很难......
  • linux下如何查看某软件是否已安装
    因为linux安装软件的方式比较多,所以没有一个通用的办法能查到某些软件是否安装了。总结起来就是这样几类:1、rpm包安装的,可以用rpm-qa看到,如果要查找某软件包是否安装,用r......
  • 延迟分配:提供内存利用率的三种机制
    为了提供内存利用率,有一些奇妙的机制,本节就来介绍下:写时复制,请求调页和mmap系统调用写时复制写时复制,可概括为写时复制是一种计算机编程领域中的优化技术(Copy-on-Write,......
  • Linux 网卡实时流量查看脚本
    Linux网卡实时流量查看脚本#!/bin/bashPATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin;exportPATHfunctiontraffic_monitor{OS_NAME=$......
  • C++ 自学笔记 new和delete(动态内存分配)
    动态内存分配DynamicmemoeyallocationC++使用new和delete来申请和释放内存new:先申请一个空间int\Stash:默认构造函数初始化对象~:析构函数析构delete:再释放空间......
  • 【Redis】Key过期了为什么内存没有释放
    SET除了可以设置key-value之外,还可以设置key的过期时间。  如果想要修改key的值,使用set命令,而没有加上过期时间的参数,那么这个key的过期时间将会被擦除。......
  • linux文件内容查看命令 实验报告
    实验任务Linux查看文件基础命令 实验环境一台centos7 实验步骤1.显示文件全部内容Cat+想要查看的文件名  2.显示文件全部内容并加行号  3.空行不......
  • 驱动开发:内核CR3切换读写内存
    首先CR3是什么,CR3是一个寄存器,该寄存器内保存有页目录表物理地址(PDBR地址),其实CR3内部存放的就是页目录表的内存基地址,运用CR3切换可实现对特定进程内存地址的强制读写操......
  • 1.springsecurity基于内存和数据库的认证
    1.总结:昨天主要是使用security实现了基于内存的认证和基于数据库的认证(实际项目中使用);在security的项目中,必须配置WebSecurityConfigurerAdaptor的实现类来重写它的基于......
  • golang goroutine协程泄露
      语言级别的并发支持是Go的一大优势,但这个优势也很容易被滥用。通常我们在开始Go并发学习时,常常听别人说,Go的并发非常简单,在调用函数前加上go关键词便可启动g......