From de938eb621c5f464ae4cf90414fe5ec34a9ab1a2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 28 Feb 2016 11:40:39 +0100 Subject: [PATCH] db/simple: handle exception in Open() properly, fix memory leak --- .../plugins/simple/SimpleDatabasePlugin.cxx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index b0ac24c20..cbc2c96d8 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -198,7 +198,7 @@ SimpleDatabase::Load(Error &error) bool SimpleDatabase::Open(Error &error) -try { +{ assert(prefixed_light_song == nullptr); root = Directory::NewRoot(); @@ -208,9 +208,20 @@ try { borrowed_song_count = 0; #endif - Error error2; - if (!Load(error2)) { - LogError(error2); + try { + Error 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; @@ -221,9 +232,6 @@ try { } return true; -} catch (const std::exception &e) { - error.Set(std::current_exception()); - return false; } void