Commit 9f0ddf0e authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

namespaces: don't leak memory on error paths

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: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent fbcf1e14
...@@ -136,11 +136,11 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts) ...@@ -136,11 +136,11 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts)
{ {
struct join_ns *jn; struct join_ns *jn;
jn = xmalloc(sizeof(*jn)); if (check_ns_file(ns_file))
if (!jn)
return -1; return -1;
if (check_ns_file(ns_file)) jn = xmalloc(sizeof(*jn));
if (!jn)
return -1; return -1;
jn->ns_file = ns_file; jn->ns_file = ns_file;
...@@ -154,13 +154,13 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts) ...@@ -154,13 +154,13 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts)
jn->nd = &ipc_ns_desc; jn->nd = &ipc_ns_desc;
join_ns_flags |= CLONE_NEWIPC; join_ns_flags |= CLONE_NEWIPC;
} else if (!strncmp(type, "pid", 4)) { } else if (!strncmp(type, "pid", 4)) {
pr_perror("join-ns pid namespace not supported\n"); pr_err("join-ns pid namespace not supported\n");
return -1; goto err;
} else if (!strncmp(type, "user", 5)) { } else if (!strncmp(type, "user", 5)) {
jn->nd = &user_ns_desc; jn->nd = &user_ns_desc;
if (set_user_extra_opts(jn, extra_opts)) { if (set_user_extra_opts(jn, extra_opts)) {
pr_perror("invalid user namespace extra_opts %s\n", extra_opts); pr_err("invalid user namespace extra_opts %s\n", extra_opts);
return -1; goto err;
} }
join_ns_flags |= CLONE_NEWUSER; join_ns_flags |= CLONE_NEWUSER;
} else if (!strncmp(type, "mnt", 4)) { } else if (!strncmp(type, "mnt", 4)) {
...@@ -168,12 +168,15 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts) ...@@ -168,12 +168,15 @@ int join_ns_add(const char *type, char *ns_file, char *extra_opts)
join_ns_flags |= CLONE_NEWNS; join_ns_flags |= CLONE_NEWNS;
} else { } else {
pr_perror("invalid namespace type %s\n", type); pr_perror("invalid namespace type %s\n", type);
return -1; goto err;
} }
list_add_tail(&jn->list, &opts.join_ns); list_add_tail(&jn->list, &opts.join_ns);
pr_info("Added %s:%s join namespace\n", type, ns_file); pr_info("Added %s:%s join namespace\n", type, ns_file);
return 0; return 0;
err:
xfree(jn);
return -1;
} }
static unsigned int parse_ns_link(char *link, size_t len, struct ns_desc *d) static unsigned int parse_ns_link(char *link, size_t len, struct ns_desc *d)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment