summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/JSONCompilationDatabase.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-08-08 16:06:15 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-08-08 16:06:15 +0000
commitcdba84c0d309be4312b08d0e7daa293c5305eba4 (patch)
tree76b02ab4e181c1519c6ca40294ebcb34c59df1fd /clang/lib/Tooling/JSONCompilationDatabase.cpp
parent590e5ff473fba9dcace9eee5fc59cb321a22811f (diff)
downloadbcm5719-llvm-cdba84c0d309be4312b08d0e7daa293c5305eba4.tar.gz
bcm5719-llvm-cdba84c0d309be4312b08d0e7daa293c5305eba4.zip
CompilationDatabase: Sure-up ownership of compilation databases using std::unique_ptr
Diving into the memory leaks fixed by r213851 there was one case of a memory leak of a CompilationDatabase due to not properly taking ownership of the result of "CompilationDatabase::autoDetectFromSource". Given that both implementations and callers have been using unique_ptr to own CompilationDatabase objects - make this explicit in the API to reduce the risk of further leaks. llvm-svn: 215215
Diffstat (limited to 'clang/lib/Tooling/JSONCompilationDatabase.cpp')
-rw-r--r--clang/lib/Tooling/JSONCompilationDatabase.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 8b8bd293851..088b42a0e4b 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -118,15 +118,15 @@ std::vector<std::string> unescapeCommandLine(
}
class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin {
- CompilationDatabase *loadFromDirectory(StringRef Directory,
- std::string &ErrorMessage) override {
+ std::unique_ptr<CompilationDatabase>
+ loadFromDirectory(StringRef Directory, std::string &ErrorMessage) override {
SmallString<1024> JSONDatabasePath(Directory);
llvm::sys::path::append(JSONDatabasePath, "compile_commands.json");
std::unique_ptr<CompilationDatabase> Database(
JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage));
if (!Database)
return nullptr;
- return Database.release();
+ return Database;
}
};
@@ -141,7 +141,7 @@ X("json-compilation-database", "Reads JSON formatted compilation databases");
// and thus register the JSONCompilationDatabasePlugin.
volatile int JSONAnchorSource = 0;
-JSONCompilationDatabase *
+std::unique_ptr<JSONCompilationDatabase>
JSONCompilationDatabase::loadFromFile(StringRef FilePath,
std::string &ErrorMessage) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> DatabaseBuffer =
@@ -154,10 +154,10 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
new JSONCompilationDatabase(DatabaseBuffer->release()));
if (!Database->parse(ErrorMessage))
return nullptr;
- return Database.release();
+ return Database;
}
-JSONCompilationDatabase *
+std::unique_ptr<JSONCompilationDatabase>
JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString,
std::string &ErrorMessage) {
std::unique_ptr<llvm::MemoryBuffer> DatabaseBuffer(
@@ -166,7 +166,7 @@ JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString,
new JSONCompilationDatabase(DatabaseBuffer.release()));
if (!Database->parse(ErrorMessage))
return nullptr;
- return Database.release();
+ return Database;
}
std::vector<CompileCommand>
OpenPOWER on IntegriCloud