[clang] [analyzer] MallocChecker – Fix false positive leak for smart pointers in temporary objects (PR #152751)
Ivan Murashko via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 30 16:58:29 PDT 2025
================
@@ -3194,7 +3480,6 @@ void MallocChecker::checkEscapeOnReturn(const ReturnStmt *S,
if (!Sym)
// If we are returning a field of the allocated struct or an array element,
// the callee could still free the memory.
- // TODO: This logic should be a part of generic symbol escape callback.
----------------
ivanmurashko wrote:
The change is not directly related to the PR. I believe that the TODO comment became obsolete a long time ago, and I deleted it for that reason.
The TODO comment was added in February 2012 (see 4ca45b1d00e97c590bc1bf012bd35b1f73926565) when fixing a false positive in the malloc checker related to returning fields of allocated structs or array elements via pointer arithmetic. The author of the commit embedded escape-on-return logic directly in `checkPreStmt` but recognized this was architecturally suboptimal, suggesting it should be part of a "generic symbol escape callback" instead.
This TODO was rendered unnecessary when commit 122171e235827 refactored the code by extracting the escape logic into a dedicated `checkEscapeOnReturn` method that could be reused by multiple callbacks (`checkPreStmt` and `checkEndFunction`). This addressed the architectural concern without requiring a complete redesign of the symbol escape callback system.
https://github.com/llvm/llvm-project/pull/152751
More information about the cfe-commits
mailing list