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

David Blaikie dblaikie at gmail.com
Wed Apr 23 22:09:02 PDT 2014


On Wed, Apr 23, 2014 at 9:26 PM, Nico Weber <nicolasweber at gmx.de> wrote:
> 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?

Certainly. Feel free to do so to any APIs you like, basically. Like
the rest of the C++11 migration, it's pretty much an ad-hoc,
as-needed, when-bored, etc kind of thing.

> 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;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list