From 38076677c7113bae4b50f7989ec45ebf521eae23 Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Fri, 30 Aug 2024 12:51:20 +0200 Subject: rest: memleak in error path of image/create if obtaining repository IP fails, json object for client is leaked, move it after query to infer repository IP. --- src/rest.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/rest.c') diff --git a/src/rest.c b/src/rest.c index f4b5918..647458e 100644 --- a/src/rest.c +++ b/src/rest.c @@ -3710,7 +3710,7 @@ static int og_cmd_add_image(json_t *element, struct og_msg_params *params, char repository_ip[OG_DB_IP_MAXLEN + 1]; char new_image_id[OG_DB_INT_MAXLEN + 1]; struct og_dbi *dbi; - json_t *clients; + json_t *body; int err = 0; bool found; @@ -3766,20 +3766,19 @@ static int og_cmd_add_image(json_t *element, struct og_msg_params *params, } json_object_set_new(element, "id", json_string(params->id)); - clients = json_copy(element); - json_object_del(clients, "clients"); - err = og_dbi_get_repository_ip(dbi, params->image.repo_id, params->ips_array[0], repository_ip); og_dbi_close(dbi); if (err < 0) return err; - json_object_set_new(clients ,"repository", json_string(repository_ip)); - json_object_set_new(clients ,"backup", json_boolean(params->backup)); + body = json_copy(element); + json_object_del(body, "clients"); + json_object_set_new(body, "repository", json_string(repository_ip)); + json_object_set_new(body, "backup", json_boolean(params->backup)); return og_send_request(OG_METHOD_POST, OG_CMD_IMAGE_CREATE, params, - clients); + body); } static int og_cmd_create_image(json_t *element, struct og_msg_params *params) -- cgit v1.2.3-18-g5258