A resource leak occurs when a program fails to release a finite resource like a socket, file descriptor or database connection. While sound static analysis tools can detect all leaks, automatically repairing them remains challenging. Prior work took the output of a detection tool and attempted to repair only leaks from a hard-coded list of library resource types. That approach limits the scope of repairable leaks: real-world code uses resource wrappers that store a resource in a field and must themselves be closed. This paper makes four key contributions to improve resource leak repair in the presence of wrappers. (1) It integrates inference of resource management specifications into the repair pipeline, enabling extant fixing approaches to reason about wrappers. (2) It transforms programs into variants that are easier to analyze, making inference, detection, and fixing tools more effective; for instance, it makes detection tools report problems closer to the root cause, often in a client of a resource wrapper rather than within the wrapper class itself. (3) A novel field containment analysis reasons about resource lifetimes, enabling repair of more leaks involving resources stored in fields. (4) It introduces a new repair pattern and more precise reasoning to better handle resources stored in non-final fields. Prior work fixed 41% of resource leak warnings in the NJR benchmark suite; our implementation Arodnap fixes 68%.
翻译:资源泄漏是指程序未能释放有限资源(如套接字、文件描述符或数据库连接)的情况。虽然可靠的静态分析工具能够检测所有泄漏,但自动修复这些泄漏仍然具有挑战性。先前的研究工作基于检测工具的输出,仅尝试修复预定义库资源类型列表中的泄漏。该方法限制了可修复泄漏的范围:实际代码中广泛使用资源包装器,这类包装器将资源存储在字段中且自身必须被显式关闭。本文针对包装器环境下的资源泄漏修复问题提出了四项关键贡献:(1)将资源管理规约推断集成至修复流程中,使现有修复方法能够对包装器进行推理;(2)通过程序变换生成更易分析的变体,提升推断、检测与修复工具的效果;例如,该方法使检测工具能更接近根本原因地报告问题,通常定位在资源包装器的客户端代码而非包装器类内部。(3)新颖的字段包含分析能够推理资源生命周期,从而修复更多涉及字段存储资源的泄漏。(4)引入新的修复模式及更精确的推理机制,以更好地处理非final字段中存储的资源。先前的研究在NJR基准测试集中修复了41%的资源泄漏警告;我们实现的Arodnap系统修复率达到68%。