From 2ad3713e8cdb137da71ce8df4cd905e472d05bc3 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuermann Date: Wed, 3 Jun 2015 23:12:34 +0200 Subject: [PATCH] JSON: Fix memory leak in parser - Fix JSON root object leaking out by using delete. This is by no means a comprehensive fix since exceptions are involved in a lot of places, but it does fix the memory leak in all cases checked in Taskwarrior's test suite. - Going with a shared_ptr or unique_ptr here might be a better solution, but would involve more code changes. --- src/Hooks.cpp | 4 ++++ src/Task.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 84c790c67..9eca0bf3d 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -426,6 +426,8 @@ void Hooks::assertValidJSON (const std::vector & input) const context.error (STRING_HOOK_ERROR_NOUUID); throw 0; } + + delete root; } catch (const std::string& e) @@ -479,6 +481,8 @@ void Hooks::assertSameTask (const std::vector & input, const Task& context.error (format (STRING_HOOK_ERROR_SAME2, uuid, json_uuid)); throw 0; } + + delete root_obj; } } diff --git a/src/Task.cpp b/src/Task.cpp index f316e7471..b7b64e753 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -706,6 +706,8 @@ void Task::parseJSON (const std::string& line) } } } + + delete root; } ////////////////////////////////////////////////////////////////////////////////