From 1ff0cc4cff8cde0f93efc4b88d639a7d9900162e Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 1 Sep 2023 09:47:54 -0700 Subject: [PATCH] AST: leak memory rather than corrupt memory `llvm::MallocAllocator` uses `operator new`, not `malloc`. This memory may not be `free`'ed but must be `delete`d. However, this is also not guaranteed. Instead, we should have a global bump allocator or a global `llvm::MallocAllocator` that uses `Allocate` and `Deallocate` to manage this memory. --- lib/AST/CASTBridging.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/AST/CASTBridging.cpp b/lib/AST/CASTBridging.cpp index e629b4057b0e9..bc88b4f164cc3 100644 --- a/lib/AST/CASTBridging.cpp +++ b/lib/AST/CASTBridging.cpp @@ -31,9 +31,10 @@ struct BridgedDiagnosticImpl { ~BridgedDiagnosticImpl() { inFlight.flush(); - for (auto text : textBlobs) { - free((void *)text.data()); - } + /* + for (auto &text : textBlobs) + BridgedDiagnosticImpl::Allocator.Deallocate(&text); + */ } }; } // namespace