]> granicus.if.org Git - clang/commitdiff
Fix two test-only leaks found by LSan.
authorNico Weber <nicolasweber@gmx.de>
Thu, 24 Apr 2014 04:26:18 +0000 (04:26 +0000)
committerNico Weber <nicolasweber@gmx.de>
Thu, 24 Apr 2014 04:26:18 +0000 (04:26 +0000)
The result of getBufferForFile() must be freed.
(Should we change functions that expect the caller to assume ownership so
that they return unique_ptrs instead? Then the type system makes sure we get
this right.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207074 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/Tooling/RefactoringTest.cpp
unittests/Tooling/RewriterTestContext.h

index 8c7bfa1c767a344924b1a3d6f60dc3975bf824aa..b1ed3c72be84363b0f131dc02b0fee2524626811 100644 (file)
@@ -252,7 +252,9 @@ public:
     // descriptor, which might not see the changes made.
     // FIXME: Figure out whether there is a way to get the SourceManger to
     // reopen the file.
-    return Context.Files.getBufferForFile(Path, NULL)->getBuffer();
+    std::unique_ptr<const llvm::MemoryBuffer> FileBuffer(
+        Context.Files.getBufferForFile(Path, NULL));
+    return FileBuffer->getBuffer();
   }
 
   llvm::StringMap<std::string> TemporaryFiles;
index 841cd0f9097b5b2a5184a32a48e208c7b9815b2c..a1bb2311c55f68d9c326dac88b4b53219489982d 100644 (file)
@@ -102,7 +102,9 @@ class RewriterTestContext {
     // descriptor, which might not see the changes made.
     // FIXME: Figure out whether there is a way to get the SourceManger to
     // reopen the file.
-    return Files.getBufferForFile(Path, NULL)->getBuffer();
+    std::unique_ptr<const llvm::MemoryBuffer> FileBuffer(
+        Files.getBufferForFile(Path, NULL));
+    return FileBuffer->getBuffer();
   }
 
   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;