
软件学报 ISSN 1000-9825, CODEN RUXUEW E-mail: jos@iscas.ac.cn
Journal of Software,2019,30(5):1330−1341 [doi: 10.13328/j.cnki.jos.005715] http://www.jos.org.cn
©中国科学院软件研究所版权所有. Tel: +86-10-62562563
C 程序内存泄漏智能化检测方法
∗
朱亚伟
,
左志强
,
王林章
,
李宣东
(计算机软件新技术国家重点实验室(南京大学),江苏 南京 210023)
通讯作者: 王林章, E-mail: lzwang@nju.edu.cn
摘 要: 内存泄漏在采用显式内存管理机制的 C 语言中是一种常见的代码缺陷,内存泄漏的检测方法目前主要是
静态分析与动态检测.动态检测开销大,且高度依赖测试用例;静态分析目前被学术界和工业界广泛应用,但是存在
大量误报,需要人工对检测结果进行确认.内存泄漏静态分析的误报通常是由于对指针、分支语句和全局变量分析
的不准确性导致的.提出了一种内存泄漏的智能化检测方法,通过使用机器学习算法学习程序特征与内存泄漏之间
的相关性,构建机器学习分类器,并应用机器学习分类器进一步提高内存泄漏静态分析的准确性.首先构建机器学习
分类器,然后通过静态分析方法构建从内存分配点开始的 Sparse Value Flow Graph(SVFG),并从中提取内存泄漏相
关特征,再使用规则和机器学习分类器进行内存泄漏的检测.实验结果显示,该方法在分析指针、分支语句和全局变
量时是有效的,能够提高内存泄漏检测的准确性,降低内存泄漏检测结果的误报.最后,对未来研究的可行性以及面
临的挑战进行了展望.
关键词: 内存泄漏;内存泄漏检测;静态分析;机器学习;特征提取
中图法分类号: TP311
中文引用格式: 朱亚伟,左志强,王林章,李宣东.C 程序内存泄漏智能化检测方法.软件学报,201 9,30(5):1330 −1341. http://
www.jos.org .cn/1000-9825/5715 .htm
英文引用格式: Zhu YW, Zuo ZQ, Wang LZ, Li XD. Memory leak intelligent detection method for C programs. Ruan Jian Xue
Bao/Journal of Software, 2019 ,30(5):1330−1341 (in Chin ese). http://www.jos.org.cn/1000-9825/5715 .htm
Memory Leak Intelligent De tection Metho d for C Programs
ZHU Ya-Wei, ZUO Zhi-Qiang, WANG Lin-Zhang, LI Xuan-Dong
(State Key Laboratory for Novel Software Technology (Nanjing University), Nanjing 210023, China)
Abstra ct : Memory leak is a common code bug for C programs which uses explicit memory management mechanisms. At present, the
main detection methods of memory leaks are static analysis and dynamic detection. Dynamic d etection has huge overhead and it is highly
dependent on test cases. Static analysis is widely used by academic and industry, but there are a large number of false positives, which
need to be manually confirmed. Inaccuracy in the analysis of pointers, branch statements, and global variables leads to false positives in
static analysis of memory leaks. In this study, an intelligent detection method is proposed for memory leak. By using machine learning
algorithms to learn the correlation between program’s features and memory leaks, a machine learning classifier is built and applied to
improve the accuracy of static analysis of memory leaks. Firstly, a machine learning classifier is trained. Then, the sparse value flow
graph (SVFG) starting from allocation should be constructed by using the static analysis, the features related to memory leaks can be
extracted from the SVFG. Lastly, the memory leaks are detected by using rules and machin e learning classifier. Experiment al results show
∗ 基金项目: 国家重点研发计划(2016YFB1000802); 国家自然科学基金(61802168, 6163201 5); 中央高校基本科研业务费专项资
金(020214380047)
Foundation item: National Key Research and Development Program of China (2016YFB1000802); National Natural Science
Foundation of China (61802168, 61632015); Fund amental Research Funds for th e Central Universiti es (020214380047)
本文由智能化软件新技术专刊特约编辑申富饶教授和李戈副教授推荐.
收稿时间: 2018-08-29; 修改时间: 2018-10-31; 采用时间: 2018-12-13
评论