From 76c0a05f28531bcab3f89a4dfccae4b9b8eaf72c Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Tue, 30 Jun 2020 12:39:29 +0200 Subject: #980 Fix memleak in og_cmd_scope_get If either root or children_root fail to be created but the other one does not, then reserved memory for the successful one would not be freed. --- src/rest.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rest.c b/src/rest.c index 43871e4..2a90028 100644 --- a/src/rest.c +++ b/src/rest.c @@ -2445,9 +2445,14 @@ static int og_cmd_scope_get(json_t *element, struct og_msg_params *params, }; root = json_object(); + if (!root) + return -1; + children_root = json_array(); - if (!root || !children_root) + if (!children_root) { + json_decref(root); return -1; + } json_object_set(root, "scope", children_root); -- cgit v1.2.3-18-g5258