mirror of https://git.48k.eu/ogserver
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.master
parent
8c37aa3688
commit
38076677c7
13
src/rest.c
13
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 repository_ip[OG_DB_IP_MAXLEN + 1];
|
||||||
char new_image_id[OG_DB_INT_MAXLEN + 1];
|
char new_image_id[OG_DB_INT_MAXLEN + 1];
|
||||||
struct og_dbi *dbi;
|
struct og_dbi *dbi;
|
||||||
json_t *clients;
|
json_t *body;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
bool found;
|
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));
|
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,
|
err = og_dbi_get_repository_ip(dbi, params->image.repo_id,
|
||||||
params->ips_array[0], repository_ip);
|
params->ips_array[0], repository_ip);
|
||||||
og_dbi_close(dbi);
|
og_dbi_close(dbi);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
json_object_set_new(clients ,"repository", json_string(repository_ip));
|
body = json_copy(element);
|
||||||
json_object_set_new(clients ,"backup", json_boolean(params->backup));
|
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,
|
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)
|
static int og_cmd_create_image(json_t *element, struct og_msg_params *params)
|
||||||
|
|
Loading…
Reference in New Issue