From 10fa0727ef3e74b3ef7bf9056f5c3d034909b391 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 15 Feb 2020 14:12:21 +0200 Subject: [PATCH] server: clear up move_docid Ensure all paths free resources --- mu/mu-cmd-server.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc index a1758a1a..0ccdbeac 100644 --- a/mu/mu-cmd-server.cc +++ b/mu/mu-cmd-server.cc @@ -933,24 +933,26 @@ static void move_docid (MuStore *store, DocId docid, const std::string& flagstr, bool new_name, bool no_view) { - GError *gerr{}; - auto msg{mu_store_get_msg (store, docid, &gerr)}; - if (!msg) - throw Error{Error::Code::Store, &gerr, "failed to get message from store"}; if (docid == MU_STORE_INVALID_DOCID) throw Error{Error::Code::InvalidArgument, "invalid docid"}; - const auto flags = flagstr.empty() ? mu_msg_get_flags (msg) : - get_flags (mu_msg_get_path(msg), flagstr); - if (flags == MU_FLAG_INVALID) { - mu_msg_unref(msg); - throw Error{Error::Code::InvalidArgument, "invalid flags '%s'", flagstr.c_str()}; - } + GError *gerr{}; + auto msg{mu_store_get_msg (store, docid, &gerr)}; try { + if (!msg) + throw Error{Error::Code::Store, &gerr, "failed to get message from store"}; + + const auto flags = flagstr.empty() ? mu_msg_get_flags (msg) : + get_flags (mu_msg_get_path(msg), flagstr); + if (flags == MU_FLAG_INVALID) + throw Error{Error::Code::InvalidArgument, "invalid flags '%s'", flagstr.c_str()}; + do_move (store, docid, msg, "", flags, new_name, no_view); + } catch (...) { - mu_msg_unref (msg); + if (msg) + mu_msg_unref (msg); throw; }