Skip to content

Commit

Permalink
namespaces: don't leak memory on error paths
Browse files Browse the repository at this point in the history
CID 159849 (#4 of 4): Resource leak (RESOURCE_LEAK)
15. leaked_storage: Variable jn going out of scope leaks the storage it points to.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Message-Id: <1460050184-6293-1-git-send-email-avagin@openvz.org>
  • Loading branch information
avagin committed Apr 7, 2016
1 parent e3d9167 commit ee75c76
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions criu/namespaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts)
{
struct join_ns *jn;

jn = xmalloc(sizeof(*jn));
if (!jn)
if (check_ns_file(ns_file))
return -1;

if (check_ns_file(ns_file))
jn = xmalloc(sizeof(*jn));
if (!jn)
return -1;

jn->ns_file = ns_file;
Expand All @@ -158,26 +158,29 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts)
jn->nd = &ipc_ns_desc;
join_ns_flags |= CLONE_NEWIPC;
} else if (!strncmp(type, "pid", 4)) {
pr_perror("join-ns pid namespace not supported\n");
return -1;
pr_err("join-ns pid namespace not supported\n");
goto err;
} else if (!strncmp(type, "user", 5)) {
jn->nd = &user_ns_desc;
if (set_user_extra_opts(jn, extra_opts)) {
pr_perror("invalid user namespace extra_opts %s\n", extra_opts);
return -1;
pr_err("invalid user namespace extra_opts %s\n", extra_opts);
goto err;
}
join_ns_flags |= CLONE_NEWUSER;
} else if (!strncmp(type, "mnt", 4)) {
jn->nd = &mnt_ns_desc;
join_ns_flags |= CLONE_NEWNS;
} else {
pr_perror("invalid namespace type %s\n", type);
return -1;
goto err;
}

list_add_tail(&jn->list, &opts.join_ns);
pr_info("Added %s:%s join namespace\n", type, ns_file);
return 0;
err:
xfree(jn);
return -1;
}

static unsigned int parse_ns_link(char *link, size_t len, struct ns_desc *d)
Expand Down

0 comments on commit ee75c76

Please sign in to comment.