r207074 - Fix two test-only leaks found by LSan.

Nico Weber nicolasweber at gmx.de
Wed Apr 23 21:26:18 PDT 2014


Author: nico
Date: Wed Apr 23 23:26:18 2014
New Revision: 207074

URL: http://llvm.org/viewvc/llvm-project?rev=207074&view=rev
Log:
Fix two test-only leaks found by LSan.

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.)

Modified:
    cfe/trunk/unittests/Tooling/RefactoringTest.cpp
    cfe/trunk/unittests/Tooling/RewriterTestContext.h

Modified: cfe/trunk/unittests/Tooling/RefactoringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RefactoringTest.cpp?rev=207074&r1=207073&r2=207074&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RefactoringTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RefactoringTest.cpp Wed Apr 23 23:26:18 2014
@@ -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;

Modified: cfe/trunk/unittests/Tooling/RewriterTestContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RewriterTestContext.h?rev=207074&r1=207073&r2=207074&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RewriterTestContext.h (original)
+++ cfe/trunk/unittests/Tooling/RewriterTestContext.h Wed Apr 23 23:26:18 2014
@@ -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;





More information about the cfe-commits mailing list