一句话:提出MiROK,从大规模代码中挖掘抽象资源获取/释放对并实例化为具体RAR对,提升资源泄漏检测覆盖率。
资源泄漏由获取的资源未被释放导致,现有检测技术依赖资源获取与释放(RAR)API对,但其配对池往往由人工预定义或仅从项目特定语料挖掘,覆盖库/API有限,容易漏检。本文将资源操作知识表示为抽象资源获取/释放操作对(Abs-RAR对),提出MiROK方法:在大规模代码语料上,先以规则扩展和基于学习的识别策略挖掘Abs-RAR对,再将其实例化为具体RAR对,构建更完善的RAR配对池。作者在包含1,454,224个Java方法和20,000个Maven库的语料上评估,MiROK挖掘出1,313个新Abs-RAR对,实例化为6,314个RAR对,精度达93.3%;将这些RAR对输入现有方法后,在线代码示例和开源项目中检测到更多资源泄漏缺陷。
Resource leaks, which are caused by acquired resources not being released, often result in performance degradation and system crashes. Resource leak detection relies on two essential components: identifying potential Resource Acquisition and Release (RAR) API pairs, and subsequently analyze code to uncover instances where the corresponding release API call is absent after an acquisition API call. Yet, existing techniques confine themselves to an incomplete pair pool, either pre-defined manually or mined from project-specific code corpus, thus limiting coverage across libraries/APIs and po- tentially overlooking latent resource leaks. In this work, we propose to represent resource-operation knowledge as abstract resource acquisition/release operation pairs (Abs-RAR pairs for short), and present a novel approach called MiROK to mine such Abs-RAR pairs to construct a better RAR pair pool. Given a large code corpus, MiROK first mines Abs-RAR pairs with rule-based pair expansion and learning-based pair identification strategies, and then instantiates these Abs-RAR pairs into concrete RAR pairs. We implement MiROK and apply it to mine RAR pairs from a large code corpus of 1,454,224 Java methods and 20,000 Maven libraries. We then perform an extensive evaluation to investigate the mining effectiveness of MiROK and the practical usage of its mined RAR pairs for supporting resource leak detection. Our results show that MiROK mines 1,313 new Abs-RAR pairs and instantiates them into 6,314 RAR pairs with a high precision (i.e., 93.3%). In addition, by feeding our mined RAR pairs, existing approaches detect more resource leak defects in both online code examples and open-source projects