ccmalloc是常用的内存检测工具之一,适用于Linux环境。

使用说明

官方例子:

例1:

#include <stdio.h>

void Leak(char *inStr){char *str = (char *) malloc(strlen(inStr));  memcpy(str, inStr, strlen(inStr));}

char *AvoidLeak(char *inStr){char *str = (char *) malloc(strlen(inStr));  memcpy(str, inStr, strlen(inStr));return str;}

int main(){char *str;

  Leak("This leaks 19 bytes");  str = AvoidLeak("This is not a 26 byte leak");  free(str);  str = AvoidLeak("12 byte leak");  exit(0);}

结果:

  

.--------------------------------------------------------------------------.|================ ccmalloc-0.3.8 (C) 1997-2001 Armin Biere ================|+--------------------------------------------------------------------------+| executable       = /home/faculty/donahoo/public_html/tools/ccmalloc/a.out || startup file     = .ccmalloc (but not found)                             || log file         = stderr                                                || start time       = Wed Dec 19 09:57:16 2001                              || operating system = Linux 2.4.2-2smp i686 on earth.ecs.baylor.edu         |+--------------------------------------------------------------------------+| only-count        = 0            keep-deallocated-data = 0               || check-interval    = 0            check-free-space      = 0               || check-start       = 0            file-info             = 1               || chain-length      = 0            additional-line       = 1               || check-underwrites = 0            print-addresses       = 0               || check-overwrites  = 0            print-on-one-line     = 0               || sort-by-wasted    = 1            sort-by-size          = 1               || # only-log-chain  = 0            continue              = 0               || # dont-log-chain  = 0            statistics            = 0               || debug             = 0            library-chains        = 0               || load-dynlibs      = 0            align-8-byte          = 0               || only-wasting-alloc= 1                                                    |`--------------------------------------------------------------------------'

.---------------.|ccmalloc report|=======================================================| total # of|   allocated | deallocated |     garbage |+-----------+-------------+-------------+-------------+|      bytes|          57 |          26 |          31 |+-----------+-------------+-------------+-------------+|allocations|           3 |           1 |           2 |+-----------------------------------------------------+| number of checks: 1                                 || number of counts: 4                                 || retrieving function names for addresses ... done.   || reading file info from gdb ... done.                || sorting by number of not reclaimed bytes ... done.  || number of call chains: 2                            || number of ignored call chains: 0                    || number of reported call chains: 2                   || number of internal call chains: 2                   || number of library call chains: 0                    |=======================================================|* 61.3% = 19 Bytes of garbage allocated in 1 allocation|       ||       |       0x40047306 in <???>|       ||       |       0x080493eb in <main>|       |                  at test1.c:20|       ||       |       0x0804935c in <Leak>|       |                  at test1.c:5|       ||       `-----> 0x08052fb7 in <malloc>|                          at src/wrapper.c:318|        * 38.7% = 12 Bytes of garbage allocated in 1 allocation|       ||       |       0x40047306 in <???>|       ||       |       0x0804941e in <main>|       |                  at test1.c:23|       ||       |       0x080493a4 in <AvoidLeak>|       |                  at test1.c:11|       ||       `-----> 0x08052fb7 in <malloc>|                          at src/wrapper.c:318|        `------------------------------------------------------

  

没看明白,继续再看例2

例2:

/* Test from creator of ccmalloc (http://iseran.ira.uka.de/~armin/ccmalloc/) */#include <stdio.h>#include <stdlib.h>

static char *mkstr(char *s) { return strcpy(malloc(strlen(s)+1), s);}

void f() {  mkstr("asdfasdf");}

void g(){int i;char *a[100];

for(i=0; i<100; i++)    a[i] = mkstr("in f");

  free(a[2]);  free(a[0]);}

int main(){char *a = mkstr("Hallo"), *b;

  (void) mkstr("Test");

  f();

  b = mkstr("Test");

  g();

  a[6]=0;

  free(b);  free(a);

  exit(0);return 1;}

使用CCMalloc结果:

.--------------------------------------------------------------------------.|================ ccmalloc-0.3.8 (C) 1997-2001 Armin Biere ================|+--------------------------------------------------------------------------+| executable       = /home/faculty/donahoo/public_html/tools/ccmalloc/a.out || startup file     = .ccmalloc (but not found)                             || log file         = stderr                                                || start time       = Wed Dec 19 10:05:49 2001                              || operating system = Linux 2.4.2-2smp i686 on earth.ecs.baylor.edu         |+--------------------------------------------------------------------------+| only-count        = 0            keep-deallocated-data = 0               || check-interval    = 0            check-free-space      = 0               || check-start       = 0            file-info             = 1               || chain-length      = 0            additional-line       = 1               || check-underwrites = 0            print-addresses       = 0               || check-overwrites  = 0            print-on-one-line     = 0               || sort-by-wasted    = 1            sort-by-size          = 1               || # only-log-chain  = 0            continue              = 0               || # dont-log-chain  = 0            statistics            = 0               || debug             = 0            library-chains        = 0               || load-dynlibs      = 0            align-8-byte          = 0               || only-wasting-alloc= 1                                                    |`--------------------------------------------------------------------------'

.---------------.|ccmalloc report|=======================================================| total # of|   allocated | deallocated |     garbage |+-----------+-------------+-------------+-------------+|      bytes|         525 |          21 |         504 |+-----------+-------------+-------------+-------------+|allocations|         104 |           4 |         100 |+-----------------------------------------------------+| number of checks: 1                                 || number of counts: 108                               || retrieving function names for addresses ... done.   || reading file info from gdb ... done.                || sorting by number of not reclaimed bytes ... done.  || number of call chains: 3                            || number of ignored call chains: 0                    || number of reported call chains: 3                   || number of internal call chains: 3                   || number of library call chains: 0                    |=======================================================|* 97.2% = 490 Bytes of garbage allocated in 98 allocations|       ||       |       0x40047306 in <???>|       ||       |       0x0804944a in <main>|       |                  at test2.c:36|       ||       |       0x080493b9 in <g>|       |                  at test2.c:20|       ||       |       0x08049360 in <mkstr>|       |                  at test2.c:7|       ||       `-----> 0x08053007 in <malloc>|                          at src/wrapper.c:318|        |  1.8% = 9 Bytes of garbage allocated in 1 allocation|       ||       |       0x40047306 in <???>|       ||       |       0x08049430 in <main>|       |                  at test2.c:32|       ||       |       0x0804938b in <f>|       |                  at test2.c:11|       ||       |       0x08049360 in <mkstr>|       |                  at test2.c:7|       ||       `-----> 0x08053007 in <malloc>|                          at src/wrapper.c:318|        |  0.10% = 5 Bytes of garbage allocated in 1 allocation|       ||       |       0x40047306 in <???>|       ||       |       0x08049428 in <main>|       |                  at test2.c:30|       ||       |       0x08049360 in <mkstr>|       |                  at test2.c:7|       ||       `-----> 0x08053007 in <malloc>|                          at src/wrapper.c:318|        `------------------------------------------------------

  

内存泄露检测之ccmalloc相关推荐

  1. Ubuntu下内存泄露检测工具Valgrind的使用

    在VS中可以用VLD检测是否有内存泄露,可以参考http://blog.csdn.net/fengbingchun/article/details/44195959,下面介绍下Ubuntu中内存泄露检 ...

  2. android native堆内存泄露,Android Native内存泄露检测

    Android Studio没有提供直接的Native层的内存泄露检测工具,但我们仍可以通过开源工具进行动态检测和静态检测 动态检测 在APP运行时进行检测,就像LeakCanary Update: ...

  3. Android NDK 内存泄露检测

    前言 最近写C++代码,老是担心代码存在内存泄露,胆战心惊的,Andorid中Java层代码内存泄露可以借助leakcanary进行检测:找了一番,找到了PC上C++上的内存泄露检测库LeakTrac ...

  4. memwatch内存泄露检测工具

    工具介绍 官网 http://www.linkdata.se/sourcecode/memwatch/ 其功能如下官网介绍,挑选重点整理: 1. 号称功能: 内存泄露检测 (检测未释放内存, 即 动态 ...

  5. DevPartner Studio Professional Edition 11 内存泄露检测使用

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! DevP ...

  6. UE3 MemLeakCheck Tracking(内存泄露检测追踪)

    MemLeakCheck Tracking(内存泄露检测追踪) 概述 运行 MemLeakCheck MemLeakCheck MemLeakCheck -fast Release vs. Test ...

  7. 转载浅谈MFC内存泄露检测及内存越界访问保护机制

    2019独角兽企业重金招聘Python工程师标准>>> 本文所有代码均在VC2008下编译.调试.如果您使用的编译器不同,结果可能会有差别,但本文讲述的原理对于大部分编译器应该是相似 ...

  8. 精准 iOS 内存泄露检测工具

    MLeaksFinder:精准 iOS 内存泄露检测工具 发表于 2016-02-22   |   zepo   |   23 Comments 背景 平常我们都会用 Instrument 的 Lea ...

  9. arm linux下交叉编译valgrind工具进行内存泄露检测和性能分析

    C/C++等底层语言在提供强大功能及性能的同时,其灵活的内存访问也带来了各种纠结的问题.如果crash的地方正是内存使用错误的地方,说明你人品好.如果crash的地方内存明显不是consistent的 ...

最新文章

  1. 华硕ac68u最佳设置_灵耀X2 Pro和ARTone双双登场 华硕一举承包轻奢创作
  2. 如何制作EDM邮件的内容
  3. double转换为int以及浮点型相加损失精度问题
  4. UITableVeiw相关的需求解决
  5. 老板:kill -9 的原理都不知道就敢去线上执行?明天不用来了
  6. iOS快速开发框架--Bee Framework
  7. Keil uvision 5 MDK 安装教程
  8. mysql跨服务器查询插入_Oracle跨服务器查询插入数据
  9. 【CodeForces - 574C】Bear and Poker(思维,剪枝,数学)
  10. LeetCode 355. 设计推特(哈希map+set)
  11. 他受他爸影响,他爸受数学家影响,最终造出了自动旋转的房子!
  12. 面试精讲之面试考点及大厂真题 - 分布式专栏 01 开篇词:我是怎样带你通过大厂面试
  13. abaqus切削为什么没有切屑_切削液降温6大绝招,肯定有一款适合你
  14. 编写kernel第一个Hello World
  15. 基于深度学习的问答系统论文
  16. python学习_循环结构 and 类型判断
  17. 利用【数据链接属性】对话框,创建连接字符串
  18. 【基础入门题031】三色球问题
  19. spacy教程--基础
  20. H2O技术方案预研分析

热门文章

  1. mySql学习笔记:比sql server书写要简单
  2. 屌丝就爱尝鲜头——java8再判断
  3. Puppet常用配置与管理
  4. CISCO路由器的备份与还原(1)
  5. python grouo by_在python中实现数据库下group by功能
  6. Android桌面组件开发之实时文件夹(Live_Folders)
  7. Android - get email attachment name in my application
  8. 策略模式实现支持多种类数据库的DBHelp
  9. 深入动态人脸识别小场景应用,2019年或将迎来爆发期
  10. window8服务器