Skip to content

Commit

Permalink
cgroups: don't leak memory on a error path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
avagin committed Mar 2, 2018
1 parent 93b5393 commit 5f94389
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/c/criu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5f94389

Please sign in to comment.