This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8afabff6b11c: Frontend: Fix memory leak in 
CompilerInstance::setVerboseOutputStream (authored by dexonsmith).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93249/new/

https://reviews.llvm.org/D93249

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/unittests/Frontend/OutputStreamTest.cpp


Index: clang/unittests/Frontend/OutputStreamTest.cpp
===================================================================
--- clang/unittests/Frontend/OutputStreamTest.cpp
+++ 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<raw_null_ostream>());
+
+  // Trust leak sanitizer bots to catch a leak here.
+  Compiler.setVerboseOutputStream(llvm::nulls());
+}
+
 } // anonymous namespace
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -85,7 +85,7 @@
 }
 
 void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
-  OwnedVerboseOutputStream.release();
+  OwnedVerboseOutputStream.reset();
   VerboseOutputStream = &Value;
 }
 


Index: clang/unittests/Frontend/OutputStreamTest.cpp
===================================================================
--- clang/unittests/Frontend/OutputStreamTest.cpp
+++ 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<raw_null_ostream>());
+
+  // Trust leak sanitizer bots to catch a leak here.
+  Compiler.setVerboseOutputStream(llvm::nulls());
+}
+
 } // anonymous namespace
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -85,7 +85,7 @@
 }
 
 void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
-  OwnedVerboseOutputStream.release();
+  OwnedVerboseOutputStream.reset();
   VerboseOutputStream = &Value;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D93249: Fr... Duncan P. N. Exon Smith via Phabricator via cfe-commits
    • [PATCH] D9324... Erik Pilkington via Phabricator via cfe-commits
    • [PATCH] D9324... Duncan P. N. Exon Smith via Phabricator via cfe-commits

Reply via email to