🍒[lldb][ClangModulesDeclVendor] Fix use-after-free of diagnostics stream #11808
+4
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This got exposed by
09262656f32ab3f2e1d82e5342ba37eecac52522.The underlying stream of
m_osis referenced by theTextDiagnosticmember ofTextDiagnosticPrinter. It got turned into allvm::formatted_raw_ostreamin the commit above. When~TextDiagnosticPrinter(and thus~TextDiagnostic) is invoked, we now call~formatted_raw_ostream, which tries to access the underlying stream. Butm_oswas already deleted because it is earlier in the order of destruction inTextDiagnosticPrinter. Move them_osmember before theTextDiagnosticPrinterto avoid a use-after-free.Drive-by:
m_outputmember which them_osholds a reference to. The fact it's a reference indicates the expectation is most likely that the string outlives the stream.The ASAN macOS bot is currently failing with this:
(cherry picked from commit b9eb974)