一句话:RLFixer 通过资源对象数据流分析区分可修复与不可修复的泄漏,为 66% 的 Java 泄漏警告生成修复,其中 95% 正确。
资源泄漏是常见且难以定位的缺陷来源,可能导致崩溃与安全漏洞;静态分析是开发期发现泄漏的主要手段,但实证研究表明开发者还需要自动修复建议。现有唯一能建议资源泄漏修复的工具 Footpatch 是通用的,效果很差:仅对 6% 的泄漏生成修复,其中只有 27% 正确。本文提出专用修复工具 RLFixer,可为任意资源泄漏检测器报告的警告生成高质量修复。其核心挑战在于:最一般的资源泄漏修复问题至少与编译期对象释放一样困难。RLFixer 借助对资源对象的数据流分析,对其逃逸方法上下文的方式进行分类,从而将编译期工具不可修复的泄漏与可修复的泄漏区分开,并为后者生成正确修复。该工具是需求驱动的,只分析与该泄漏相关的语句,因此开销较低。作者用五款流行的 Java 资源泄漏检测器产生的警告进行评估,平均为 66% 的警告生成修复,其中 95% 正确,平均修复时间为 14 秒。
Resource leaks are a common and elusive source of bugs that can result in crashes and security vulnerabilities. The most effective technique to identify such leaks during development is static analysis. However, empirical studies show that in addition to leak warnings, developers often need help in the form of automated fix suggestions to correctly repair such leaks. The only existing tool that can suggest resource-leak fixes is the general-purpose tool Footpatch. Footpatch, however, performs poorly at this task; it generates fixes for only 6% of the leaks, out of which only 27% are correct. In this paper, we introduce RLFixer, a specialized repair tool that generates high-quality fixes for resource leaks identified by any resource-leak detector. A major challenge for RLFixer is that the most general version of the resource-leak repair problem is at least as hard as compile-time object deallocation, a well-known hard problem for compilers. RLFixer tackles this issue by separating the resource-leaks that are infeasible for a compile-time tool to fix from those that are feasible to fix. RLFixer achieves this separation by using a data-flow analysis of resource objects to classify how they escape the context of their methods. The same analysis also enables RLFixer to generate correct repairs for the feasible-to-fix leaks. RLFixer is demand-driven and hence only analyzes statements relevant to the leak, thereby keeping overhead low. We evaluated RLFixer by applying it to warnings generated by five popular Java resource-leak detectors. We show that, on average, RLFixer generates repairs for 66% of their warnings, out of which 95% are correct. It has an average repair time of 14 seconds.