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

计算机工程与科学

• 高性能计算 • 上一篇    下一篇

C程序中的内存泄漏机制分析与检测方法设计

张静1,黄志球1,2,沈国华1,2,喻垚慎1,艾磊1
  

  1. (1.南京航空航天大学计算机科学与技术学院, 江苏 南京 211106;
    2.南京航空航天大学高安全系统的软件开发与验证技术工业和信息化部重点实验室,江苏 南京 211106)
  • 收稿日期:2019-09-05 修回日期:2019-12-11 出版日期:2020-05-25 发布日期:2020-05-25
  • 基金资助:

    国家重点研发计划(2018YFB1003902)

Memory leak mechanism analysis
and detection of C Programs

ZHANG Jing1,HUANG Zhi-qiu1,2,SHEN Guo-hua1,2,YU Yao-shen1,AI Lei1   

  1. (1.College of Computer Science and Technology,Nanjing University of Aeronautics and Astronautics,Nanjing 211016;
    2.Key Laboratory of Safety-Critical Software(Nanjing University of Aeronautics and Astronautics),
    Ministry of Industry and Information Technology,Nanjing 211106,China)
     
  • Received:2019-09-05 Revised:2019-12-11 Online:2020-05-25 Published:2020-05-25

摘要:

C语言作为安全关键软件的主要实现语言,其存在的内存泄漏缺陷具有很高的隐蔽性和危害性,如何保证内存泄漏检测的准确性和高效性是一大挑战。静态分析具有直接分析源码、能够较早发现软件错误,从而降低修复代价的优势。基于静态分析技术,提出了一种基于路径敏感的值流分析的内存泄漏检测方法,首先进行指针分析生成精确指向信息;然后基于指向信息构建值流约束,执行可达性分析以识别程序中的泄漏路径;最后借助指针与内存地址的有效生命周期进行验证。在典型基准C程序上的实验结果分析表明,本文方法与现有技术相比在效率和精度上都具有一定优势。
 
 

关键词: 内存泄漏, 静态分析, 指针分析, 值流分析

Abstract:

As the main implementation language of safety-critical software, memory leak defects of C language are highly concealed and harmful. How to ensure the accuracy and efficiency of memory leak detection is a big challenge. Static analysis has the advantage of directly analyzing the source code, detecting software errors early, so it can reduce the cost of repairs. Based on static analysis technology, the paper proposes a memory leak detection method based on path-sensitive value-flow analysis. Firstly, pointer analysis is performed to generate precise point-to information. Secondly, based on the point-to information, value-flow constraints are constructed, and reachability analysis is performed to identify the memory leak paths in the program. Finally, the memory leak paths are verified by the effective life cycle of pointers and memory addresses. Experimental results on typical benchmark C programs show that the proposed method can improve the efficiency and accuracy compared with the existing technology.

 
 

Key words: memory leak, static analysis, pointer analysis, value-flow analysis