[llvm] [StringMap] Move free into StringMapImpl dtor (NFC) (PR #91908)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 12 19:38:41 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
StringMapImpl allocates the memory for the table, but does not have a dtor that free it. Instead, StringMap (which inherits from StringMapImpl) contains the free call. I don't really see a good reason why this free is performed in the "wrong" class, so move it into StringMapImpl.
(I have no motivation for this change beyond seeing this in a static analyzer report.)
---
Full diff: https://github.com/llvm/llvm-project/pull/91908.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/StringMap.h (+1-1)
``````````diff
diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h
index daaf82654e094..9b58af7327391 100644
--- a/llvm/include/llvm/ADT/StringMap.h
+++ b/llvm/include/llvm/ADT/StringMap.h
@@ -53,6 +53,7 @@ class StringMapImpl {
}
StringMapImpl(unsigned InitSize, unsigned ItemSize);
+ ~StringMapImpl() { free(TheTable); }
unsigned RehashTable(unsigned BucketNo = 0);
/// LookupBucketFor - Look up the bucket that the specified string should end
@@ -203,7 +204,6 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
}
}
}
- free(TheTable);
}
using AllocTy::getAllocator;
``````````
</details>
https://github.com/llvm/llvm-project/pull/91908
More information about the llvm-commits
mailing list