summaryrefslogtreecommitdiff
path: root/src/db/Configured.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-12-18 09:17:12 +0100
committerMax Kellermann <max@duempel.org>2015-12-18 09:17:12 +0100
commit7562c5751c5c004db81ac32949b1a92232f0f2e0 (patch)
treebe8ac649d8562c9db3b7231a19fcddb22a305332 /src/db/Configured.cxx
parente6e7d6dbd654b9936b04f27b8153fb4ed945b9d3 (diff)
db/Configured: allocate ConfigBlock on the stack
Diffstat (limited to 'src/db/Configured.cxx')
-rw-r--r--src/db/Configured.cxx28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/db/Configured.cxx b/src/db/Configured.cxx
index c71195769..8f0039fd1 100644
--- a/src/db/Configured.cxx
+++ b/src/db/Configured.cxx
@@ -43,16 +43,13 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
return nullptr;
}
- ConfigBlock *allocated = nullptr;
-
- if (param == nullptr && path != nullptr) {
- allocated = new ConfigBlock(path->line);
- allocated->AddBlockParam("path", path->value.c_str(),
- path->line);
- param = allocated;
- }
-
- if (param == nullptr) {
+ if (param != nullptr)
+ return DatabaseGlobalInit(loop, listener, *param, error);
+ else if (path != nullptr) {
+ ConfigBlock block(path->line);
+ block.AddBlockParam("path", path->value.c_str(), path->line);
+ return DatabaseGlobalInit(loop, listener, block, error);
+ } else {
/* if there is no override, use the cache directory */
const AllocatedPath cache_dir = GetUserCacheDir();
@@ -65,13 +62,8 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
if (db_file_utf8.empty())
return nullptr;
- allocated = new ConfigBlock();
- allocated->AddBlockParam("path", db_file_utf8.c_str(), -1);
- param = allocated;
+ ConfigBlock block;
+ block.AddBlockParam("path", db_file_utf8.c_str(), -1);
+ return DatabaseGlobalInit(loop, listener, block, error);
}
-
- Database *db = DatabaseGlobalInit(loop, listener, *param,
- error);
- delete allocated;
- return db;
}