Skip to content

Commit 1dd34a2

Browse files
Michael137adrian-prantl
authored andcommitted
[lldb][ClangExpressionParser] Don't leak memory when multiplexing ExternalASTSources (llvm#104799)
When we use `SemaSourceWithPriorities` as the `ASTContext`s ExternalASTSource, we allocate a `ClangASTSourceProxy` (via `CreateProxy`) and two `ExternalASTSourceWrapper`. Then we push these sources into a vector in `SemaSourceWithPriorities`. The allocated `SemaSourceWithPriorities` itself will get properly deallocated because the `ASTContext` wraps it in an `IntrusiveRefCntPtr`. But the three sources we allocated earlier will never get released. This patch fixes this by mimicking what `MultiplexExternalSemaSource` does (which is what `SemaSourceWithPriorities` is based on anyway). I.e., when `SemaSourceWithPriorities` gets constructed, it increments the use count of its sources. And on destruction it decrements them. Similarly, to make sure we dealloacted the `ClangASTProxy` properly, the `ExternalASTSourceWrapper` now assumes shared ownership of the underlying source. (cherry picked from commit 770cd24)
1 parent c989f9b commit 1dd34a2

File tree

1 file changed

+1
-1
lines changed
  • lldb/source/Plugins/ExpressionParser/Clang

1 file changed

+1
-1
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace lldb_private {
3030
/// Wraps an ExternalASTSource into an ExternalSemaSource.
3131
///
3232
/// Assumes shared ownership of the underlying source.
33-
class ExternalASTSourceWrapper : public ImporterBackedASTSource {
33+
class ExternalASTSourceWrapper : public clang::ExternalSemaSource {
3434
llvm::IntrusiveRefCntPtr<ExternalASTSource> m_Source;
3535

3636
public:

0 commit comments

Comments
 (0)