diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-08-30 12:51:20 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-08-30 13:04:34 +0200 |
commit | 38076677c7113bae4b50f7989ec45ebf521eae23 (patch) | |
tree | fe0007ddc909eb78871ed78c465afa3d8bca419c | |
parent | 8c37aa368894a3062dfbb165711dfa14253783fe (diff) |
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.
-rw-r--r-- | src/rest.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -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) |