Commit de938eb6 authored by Max Kellermann's avatar Max Kellermann

db/simple: handle exception in Open() properly, fix memory leak

parent 83cc6c08
...@@ -198,7 +198,7 @@ SimpleDatabase::Load(Error &error) ...@@ -198,7 +198,7 @@ SimpleDatabase::Load(Error &error)
bool bool
SimpleDatabase::Open(Error &error) SimpleDatabase::Open(Error &error)
try { {
assert(prefixed_light_song == nullptr); assert(prefixed_light_song == nullptr);
root = Directory::NewRoot(); root = Directory::NewRoot();
...@@ -208,6 +208,7 @@ try { ...@@ -208,6 +208,7 @@ try {
borrowed_song_count = 0; borrowed_song_count = 0;
#endif #endif
try {
Error error2; Error error2;
if (!Load(error2)) { if (!Load(error2)) {
LogError(error2); LogError(error2);
...@@ -219,11 +220,18 @@ try { ...@@ -219,11 +220,18 @@ try {
root = Directory::NewRoot(); root = Directory::NewRoot();
} }
} catch (const std::exception &e) {
LogError(e);
return true; delete root;
} catch (const std::exception &e) {
error.Set(std::current_exception()); if (!Check(error))
return false; return false;
root = Directory::NewRoot();
}
return true;
} }
void void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment