基于动态插桩的CC++内存泄漏检测工具的设计与实现.pdf
第32卷第6期 计 算 机 应 用 研 究 V01.32No.6
20l5年 6月 ApplicationResearchofComputers Jun.2015
基于动态插桩的C/C++内存泄漏检测
工具的设计与实现
曾佳平,杨秋辉 汪华龙,徐保平,黄 蔚
(四川大学 计算机 (软件)学院,成都 610065)
摘 要:针对c、c++程序常出现的内存泄漏、内存越界访 问、内存的不匹配释放等错误进行了研究,分析了现
有的内存错误检测工具和方法,在基于开源的动态二进制插桩框架Pin的基础上 ,采用函数族的内存信息块管
理方法和生命周期法,实现了在Linux平台下运行的内存检测工具MemGuard原型。该原型能有效地检测出内
存泄漏、内存越界访 问、内存的不匹配释放等问题,并通过与运行在Valgrind上的工具Memcheck的对比实验证
明了该原型的有效性 以及高效性。
关键词 :内存泄漏;动态二进制插桩;生命周期 ;MemGuard原型;Valgrind
中图分类号 :TP334 文献标志码:A 文章编号:1001—3695(2015)06·1737-05
doi:10.3969/j.issn.1001—3695.2015.06.030
Designandimplementationofmemoryleakdetectiontoolof
C/C++ basedondynamicinstrumentation
ZengJiaping,YangQiuhui,WangHualong,XuBaoping,HuangWei
(CollegeofComputer(Software),SwhuanUniversity,Chengdu610065,China)
Abstract:Thispaperstudiedtheissueofmemoryleak,cross.borderaccessmemory,thememory doesnotmatchtherelease
0fC orC++ program.Bystudyingtheexistingtoolsandmethods.thispaperusedthemethodofmemoryblockinformation
managementoffunction..basedfamilyandlifecycletodevelopaprototypeofmemory leakdetectiontoolMemGuardwhichwas
basedonPinofdynamicbinaryinstrumentationframeworkofopensource.Theprototypecaneffectivelydetectmemoryleaks.
cross.borderaccessmemory ,memory doesnotmatchtherelease.Finally,throughtheComparedexperimenttoMemcheckrun.
ningontheValgrindprovesthehigheffectivenessoftheprototypeofMemGuard.
Keywords:memoryleaks;dynamicbinaryinstrumentation;lifecycle;prototypeofMemGuard;Va】 nd
C、C++因其灵活性 、高效性等特点一直以来都是主流程 Pin,设计实现了一个动态内存检测工具MemGuard,能够检测
序设计语言之一。它们与Java等高级语言相 比,在编程 中程 C/C++中出现的内存泄漏 、内存访问越界、不匹配释放 、多重
序员需要自己管理内存 ,并对程序中所涉及的内存操作有很清