]> granicus.if.org Git - clang/commitdiff
Sure-up MemoryBuffer ownership in JSONCompilationDatabase's ctor.
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 8 Aug 2014 22:01:06 +0000 (22:01 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 8 Aug 2014 22:01:06 +0000 (22:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215246 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Tooling/JSONCompilationDatabase.h
lib/Tooling/JSONCompilationDatabase.cpp

index 59451563236bfac5dfadd919c2fd01d84589b6fd..894191f30386811cbb6053ea52b2b5b7838f00e9 100644 (file)
@@ -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<llvm::MemoryBuffer> Database)
+      : Database(std::move(Database)),
+        YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// \brief Parses the database file and creates the index.
   ///
index 088b42a0e4b230b333e2390f606ac331ad4eff63..3b5f7e28d02dcef797a64e18d21971dcbcb2844d 100644 (file)
@@ -151,7 +151,7 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
     return nullptr;
   }
   std::unique_ptr<JSONCompilationDatabase> 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<llvm::MemoryBuffer> DatabaseBuffer(
       llvm::MemoryBuffer::getMemBuffer(DatabaseString));
   std::unique_ptr<JSONCompilationDatabase> Database(
-      new JSONCompilationDatabase(DatabaseBuffer.release()));
+      new JSONCompilationDatabase(std::move(DatabaseBuffer)));
   if (!Database->parse(ErrorMessage))
     return nullptr;
   return Database;