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.
This commit is contained in:
@@ -426,6 +426,8 @@ void Hooks::assertValidJSON (const std::vector <std::string>& 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 <std::string>& input, const Task&
|
||||
context.error (format (STRING_HOOK_ERROR_SAME2, uuid, json_uuid));
|
||||
throw 0;
|
||||
}
|
||||
|
||||
delete root_obj;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user