• 中国计算机学会会刊
  • 中国科技核心期刊
  • 中文核心期刊

计算机工程与科学

• 论文 • 上一篇    下一篇

基于静态检测的C++内存泄漏分析

陈贝1,许庆国1,2   

  1. (1.上海大学计算机工程与科学学院,上海 200444;2.上海市计算机软件评测重点实验室,上海 200444)
  • 收稿日期:2015-09-10 修回日期:2015-12-02 出版日期:2017-01-25 发布日期:2017-01-25
  • 基金资助:

    国家自然科学基金(61170044,61572306,61502294)

C++ program memory leakage analysis
based on static test
 

CHEN Bei1,XU Qingguo1,2   

  1. (1.School of Computer Engineering and Science,Shanghai University,Shanghai 200444;
    2.Laboratory of Computer Software Evaluating and Testing,Shanghai 200444,China)
  • Received:2015-09-10 Revised:2015-12-02 Online:2017-01-25 Published:2017-01-25

摘要:

C++是一种非常流行的计算机编程语言,在使用的过程中容易出现内存泄漏问题,而该问题往往难以识别。给出了一种对C++内存泄漏问题进行分析的方法,该方法得到C++源代码的抽象语法树,从抽象语法树中提取程序控制流图,然后将类的构造函数、普通成员函数以及析构函数的程序控制流图相互连接形成新的程序控制流图,并设计算法对控制流图进行检测。最后通过一些内存泄漏的典型实例进行测试,实验表明本方法有效。

关键词: 内存泄漏, 静态检测, 抽象语法树, 控制流图

Abstract:

C++ is a very popular computer programming language and  memory leakage is one of the most hardtofind common error in C++ programs. We design a static analyzer that can detect memory leakage for C++ programs. Firstly, we extract the control flow graph from the abstract syntax tree generated from C++ source via g++. Secondly, we build some new control flow graphs by connecting the control flow graphs of memory functions for the same class. Finally, we design and implement an algorithm to analyze the new control flow graphs to report all possible errors. Experiment results, for some examined examples, show that our method is effective.

Key words: memory leakage, static testing, abstract syntax tree, control flow graph