Boosting Static Resource Leak Detection via LLM-based Resource-Oriented Intention Inference
Chong Wang, Jianan Liu, Xin Peng, Yang Liu, Yiling Lou
TL;DR
InferROI addresses the limitations of traditional static resource-leak detectors that rely on predefined API pairs and reachability checks. It jointly leverages LLM-based inference of resource-oriented intentions (ACQ, REL, VAL) and a two-stage static path analysis to detect leaks, enabling broad coverage beyond predefined APIs. Empirical results on DroidLeaks and JLeaks show substantial improvements in bug detection and competitive false alarm rates, with additional successes in real open-source projects and cross-LLM generalization. The work demonstrates the practical potential of combining LLM-based code understanding with static analysis to enhance reliability in resource management tasks.
Abstract
Resource leaks, caused by resources not being released after acquisition, often lead to performance issues and system crashes. Existing static detection techniques rely on mechanical matching of predefined resource acquisition/release APIs and null-checking conditions to find unreleased resources, suffering from both (1) false negatives caused by the incompleteness of predefined resource acquisition/release APIs and (2) false positives caused by the incompleteness of resource reachability validation identification. To overcome these challenges, we propose InferROI, a novel approach that leverages the exceptional code comprehension capability of large language models (LLMs) to directly infer resource-oriented intentions (acquisition, release, and reachability validation) in code. InferROI first prompts the LLM to infer involved intentions for a given code snippet, and then incorporates a two-stage static analysis approach to check control-flow paths for resource leak detection based on the inferred intentions. We evaluate the effectiveness of InferROI in both resource-oriented intention inference and resource leak detection. Experimental results on the DroidLeaks and JLeaks datasets demonstrate InferROI achieves promising bug detection rate (59.3% and 62.5%) and false alarm rate (18.6% and 19.5%). Compared to three industrial static detectors, InferROI detects 14~45 and 149~485 more bugs in DroidLeaks and JLeaks, respectively. When applied to real-world open-source projects, InferROI identifies 29 unknown resource leak bugs (verified by authors), with 7 of them being confirmed by developers. In addition, the results of an ablation study underscores the importance of combining LLM-based inference with static analysis.
