rCanary: Detecting Memory Leaks Across Semi-Automated Memory Management Boundary in Rust
Rust is an effective system programming language that guarantees memory safety via compile-time verifications. It employs a novel ownership-based resource management model to facilitate automated deallocation. This model is anticipated to eliminate memory leaks. However, we observed that user intervention drives it into semi-automated memory management and makes it error-prone to cause leaks. In contrast to violating memory-safety guarantees restricted by the <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">unsafe</i> keyword, the boundary of leaking memory is implicit, and the compiler would not emit any warnings for developers. In this paper, we present <sc xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">rCanary</small>, a static, non-intrusive, and fully automated model checker to detect leaks across the semi-automated boundary. We design an encoder to abstract data with heap allocation and formalize a refined leak-free memory model based on boolean satisfiability. It can generate SMT-Lib2 format constraints for Rust MIR and is implemented as a Cargo component. We evaluate <sc xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">rCanary</small> by using flawed package benchmarks collected from the pull requests of open-source Rust projects. The results indicate that it is possible to recall all these defects with acceptable false positives. We further apply our tool to more than 1,200 real-world crates from crates.io and GitHub, identifying 19 crates having memory leaks. Our analyzer is also efficient, that costs 8.4 seconds per package.
Authors
- Hui Xu (ORCID: https://orcid.org/0000-0003-2465-8627)
- Mohan Cui (ORCID: https://orcid.org/0000-0001-5117-5829)
- Hongliang Tian (ORCID: https://orcid.org/0009-0005-1248-4078)
- Yangfan Zhou (ORCID: https://orcid.org/0000-0002-9184-7383)
Institutions
- Fudan University (CN)
Publication Details
- Journal
- IEEE Transactions on Software Engineering
- Published
- 2024-08-13
- DOI
- https://doi.org/10.1109/tse.2024.3443624
- Citations
- 2
- Primary Topic
- Advanced Data Storage Technologies
- Type
- article
- Field-Weighted Citation Impact
- 0.70
Funders
- National Natural Science Foundation of China