[llvm] [ASan][JSON] Unpoison memory before its reuse (PR #79065)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 22 22:40:30 PST 2024


================
@@ -482,6 +482,13 @@ class Value {
   friend class Object;
 
   template <typename T, typename... U> void create(U &&... V) {
+#if defined(LLVM_ADDRESS_SANITIZER_BUILD)
+    // Unpoisoning to prevent overwriting poisoned object (e.g., annotated short
+    // string). Objects that have had their memory poisoned may cause an ASan
----------------
AdvenamTacet wrote:

> there is a `destroy` method.
> could be a bug that this is not called?

`std::basic_string` destructor isn't called. I was looking for a while how I can do it better, but I failed.
Just calling `destroy()` in `create` leads to core dump `free(): invalid pointer`.

> but if it didn't call ~string, then string with buffer suppose to leak memory?
Yes. If that string is a long string, that would lead to leaking memory.
Long term, we definitely should fix that, but it seems to not be easy.

I'm still looking at it and trying to find a way to call a destructor.

PS
Scribbling in ADT may lead to leaking memory as well, but it's only in debug mode.

https://github.com/llvm/llvm-project/pull/79065


More information about the llvm-commits mailing list