diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -85,7 +85,7 @@ } void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) { - OwnedVerboseOutputStream.release(); + OwnedVerboseOutputStream.reset(); VerboseOutputStream = &Value; } diff --git a/clang/unittests/Frontend/OutputStreamTest.cpp b/clang/unittests/Frontend/OutputStreamTest.cpp --- a/clang/unittests/Frontend/OutputStreamTest.cpp +++ b/clang/unittests/Frontend/OutputStreamTest.cpp @@ -101,4 +101,12 @@ EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated")); } +TEST(FrontendOutputTests, TestVerboseOutputStreamOwnedNotLeaked) { + CompilerInstance Compiler; + Compiler.setVerboseOutputStream(std::make_unique()); + + // Trust leak sanitizer bots to catch a leak here. + Compiler.setVerboseOutputStream(llvm::nulls()); +} + } // anonymous namespace