Skip to content

Commit 8afabff

Browse files
committed
Frontend: Fix memory leak in CompilerInstance::setVerboseOutputStream
Found this memory leak in `CompilerInstance::setVerboseOutputStream` by inspection; it looks like this wasn't previously exercised, since it was never called twice. Differential Revision: https://reviews.llvm.org/D93249
1 parent 8cef455 commit 8afabff

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) {
8585
}
8686

8787
void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
88-
OwnedVerboseOutputStream.release();
88+
OwnedVerboseOutputStream.reset();
8989
VerboseOutputStream = &Value;
9090
}
9191

clang/unittests/Frontend/OutputStreamTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,12 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) {
101101
EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
102102
}
103103

104+
TEST(FrontendOutputTests, TestVerboseOutputStreamOwnedNotLeaked) {
105+
CompilerInstance Compiler;
106+
Compiler.setVerboseOutputStream(std::make_unique<raw_null_ostream>());
107+
108+
// Trust leak sanitizer bots to catch a leak here.
109+
Compiler.setVerboseOutputStream(llvm::nulls());
110+
}
111+
104112
} // anonymous namespace

0 commit comments

Comments
 (0)