Commit 8afabff6 authored by Duncan P. N. Exon Smith's avatar Duncan P. N. Exon Smith Committed by Duncan P. N. Exon Smith
Browse files

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
parent 8cef4551
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) {
}

void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
  OwnedVerboseOutputStream.release();
  OwnedVerboseOutputStream.reset();
  VerboseOutputStream = &Value;
}

+8 −0
Original line number Diff line number Diff line
@@ -101,4 +101,12 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) {
  EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
}

TEST(FrontendOutputTests, TestVerboseOutputStreamOwnedNotLeaked) {
  CompilerInstance Compiler;
  Compiler.setVerboseOutputStream(std::make_unique<raw_null_ostream>());

  // Trust leak sanitizer bots to catch a leak here.
  Compiler.setVerboseOutputStream(llvm::nulls());
}

} // anonymous namespace