免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2987 | 回复: 1
打印 上一主题 下一主题

[安装配置] valgrind-3.4.1在AIX5.3下的安装和运行 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-26 08:52 |只看该作者 |倒序浏览
通过48小时的努力,终于完成了AIX5.3下的valgrind-3.4.1的安装,现在总结一下给各位。


1)一个非法访问内存加内存泄漏的例子如下:

#include<stdlib.h>


void fun()
{
        int* p = (int*)malloc(10*sizeof(int));
        p[10] = 'a';
}

int main(int argc,char* argv[])
{
        printf("begin to leak \n");
        fun();
        printf("leak a lot \n");
        return 0;
}



2)我们使用valgrind进行检查

valgrind --tool=memcheck ./a.out
==7729550== Memcheck, a memory error detector.
==7729550== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==7729550== Using LibVEX rev 1884, a library for dynamic binary translation.
==7729550== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==7729550== Using valgrind-3.4.1, a dynamic binary instrumentation framework.
==7729550== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==7729550== For more details, rerun with: -v
==7729550==
begin to leak
==7729550== Invalid write of size 4
==7729550==    at 0x100004D4: leak (in /proc/7729550/object/a.out)
==7729550==    by 0x1000052F: main (in /proc/7729550/object/a.out)
==7729550==  Address 0x216a4050 is 0 bytes after a block of size 40 alloc'd
==7729550==    at 0xDD1ED5B0: malloc (vg_replace_malloc.c:207)
==7729550==    by 0x100004BB: leak (in /proc/7729550/object/a.out)
==7729550==    by 0x1000052F: main (in /proc/7729550/object/a.out)
leak a lot
==7729550==
==7729550== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==7729550== malloc/free: in use at exit: 40 bytes in 1 blocks.
==7729550== malloc/free: 1 allocs, 0 frees, 40 bytes allocated.
==7729550== For counts of detected errors, rerun with: -v
==7729550== searching for pointers to 1 not-freed blocks.
==7729550== checked 9,012,008 bytes.
==7729550==
==7729550== LEAK SUMMARY:
==7729550==    definitely lost: 0 bytes in 0 blocks.
==7729550==      possibly lost: 0 bytes in 0 blocks.
==7729550==    still reachable: 40 bytes in 1 blocks.
==7729550==         suppressed: 0 bytes in 0 blocks.
==7729550== Rerun with --leak-check=full to see details of leaked memory.



我在生产系统上进行了测试,效果不错,有兴趣的朋友,可以关注下,我后续补充下编译和安装的过程。

论坛徽章:
0
2 [报告]
发表于 2012-05-27 14:11 |只看该作者
楼主的后续补充呢 没了?太监了?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP