From d4497bd2814adf15f764b50ea02bffb701c03282 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 8 Aug 2014 22:01:06 +0000 Subject: [PATCH] Sure-up MemoryBuffer ownership in JSONCompilationDatabase's ctor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215246 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Tooling/JSONCompilationDatabase.h | 5 +++-- lib/Tooling/JSONCompilationDatabase.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/clang/Tooling/JSONCompilationDatabase.h b/include/clang/Tooling/JSONCompilationDatabase.h index 5945156323..894191f303 100644 --- a/include/clang/Tooling/JSONCompilationDatabase.h +++ b/include/clang/Tooling/JSONCompilationDatabase.h @@ -81,8 +81,9 @@ public: private: /// \brief Constructs a JSON compilation database on a memory buffer. - JSONCompilationDatabase(llvm::MemoryBuffer *Database) - : Database(Database), YAMLStream(Database->getBuffer(), SM) {} + JSONCompilationDatabase(std::unique_ptr Database) + : Database(std::move(Database)), + YAMLStream(this->Database->getBuffer(), SM) {} /// \brief Parses the database file and creates the index. /// diff --git a/lib/Tooling/JSONCompilationDatabase.cpp b/lib/Tooling/JSONCompilationDatabase.cpp index 088b42a0e4..3b5f7e28d0 100644 --- a/lib/Tooling/JSONCompilationDatabase.cpp +++ b/lib/Tooling/JSONCompilationDatabase.cpp @@ -151,7 +151,7 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath, return nullptr; } std::unique_ptr Database( - new JSONCompilationDatabase(DatabaseBuffer->release())); + new JSONCompilationDatabase(std::move(*DatabaseBuffer))); if (!Database->parse(ErrorMessage)) return nullptr; return Database; @@ -163,7 +163,7 @@ JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString, std::unique_ptr DatabaseBuffer( llvm::MemoryBuffer::getMemBuffer(DatabaseString)); std::unique_ptr Database( - new JSONCompilationDatabase(DatabaseBuffer.release())); + new JSONCompilationDatabase(std::move(DatabaseBuffer))); if (!Database->parse(ErrorMessage)) return nullptr; return Database; -- 2.40.0