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

This commit is contained in:
Max Kellermann 2016-02-28 11:40:39 +01:00
parent 83cc6c0835
commit de938eb621

View File

@ -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,9 +208,20 @@ try {
borrowed_song_count = 0; borrowed_song_count = 0;
#endif #endif
Error error2; try {
if (!Load(error2)) { Error error2;
LogError(error2); if (!Load(error2)) {
LogError(error2);
delete root;
if (!Check(error))
return false;
root = Directory::NewRoot();
}
} catch (const std::exception &e) {
LogError(e);
delete root; delete root;
@ -221,9 +232,6 @@ try {
} }
return true; return true;
} catch (const std::exception &e) {
error.Set(std::current_exception());
return false;
} }
void void