2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 05:18:00 +00:00

cgroups: don't leak memory on a error path

CID 161693 (#1 of 1): Resource leak (RESOURCE_LEAK)
5. leaked_storage: Variable new going out of scope leaks the storage it points to.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Andrei Vagin 2018-02-06 04:56:00 +03:00
parent e767c69b30
commit 34f16a4607

View File

@ -771,17 +771,21 @@ int criu_local_add_cg_props_file(criu_opts *opts, char *path)
int criu_local_add_cg_dump_controller(criu_opts *opts, char *name)
{
char **new;
char **new, *ctrl_name;
size_t nr;
ctrl_name = strdup(name);
if (!ctrl_name)
return -ENOMEM;
nr = opts->rpc->n_cgroup_dump_controller + 1;
new = realloc(opts->rpc->cgroup_dump_controller, nr * sizeof(char *));
if (!new)
if (!new) {
free(ctrl_name);
return -ENOMEM;
}
new[opts->rpc->n_cgroup_dump_controller] = strdup(name);
if (!new[opts->rpc->n_cgroup_dump_controller])
return -ENOMEM;
new[opts->rpc->n_cgroup_dump_controller] = ctrl_name;
opts->rpc->n_cgroup_dump_controller = nr;
opts->rpc->cgroup_dump_controller = new;