Files
clang-p2996/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.cpp
Michael Buch 770cd24140 [lldb][ClangExpressionParser] Don't leak memory when multiplexing ExternalASTSources (#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.
2024-08-20 18:40:54 +01:00

977 B