Unverified Commit cf605ce7 by Christian Brauner Committed by Stéphane Graber

lxccontainer: make sure memory is free()ed

parent b42041e4
...@@ -844,6 +844,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -844,6 +844,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
* while container is running... * while container is running...
*/ */
if (daemonize) { if (daemonize) {
bool started;
char title[2048]; char title[2048];
pid_t pid; pid_t pid;
...@@ -860,11 +861,11 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -860,11 +861,11 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
*/ */
c->pidfile = NULL; c->pidfile = NULL;
/* Prevent leaking the command socket to the second started = wait_on_daemonized_start(handler, pid);
* fork().
*/ free_init_cmd(init_cmd);
close(handler->conf->maincmd_fd); lxc_free_handler(handler);
return wait_on_daemonized_start(handler, pid); return started;
} }
/* We don't really care if this doesn't print all the /* We don't really care if this doesn't print all the
...@@ -881,8 +882,13 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -881,8 +882,13 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
SYSERROR("Error doing dual-fork"); SYSERROR("Error doing dual-fork");
exit(1); exit(1);
} }
if (pid != 0)
if (pid != 0) {
free_init_cmd(init_cmd);
lxc_free_handler(handler);
exit(0); exit(0);
}
/* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */ /* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */
if (chdir("/")) { if (chdir("/")) {
SYSERROR("Error chdir()ing to /."); SYSERROR("Error chdir()ing to /.");
...@@ -901,6 +907,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -901,6 +907,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
} else { } else {
if (!am_single_threaded()) { if (!am_single_threaded()) {
ERROR("Cannot start non-daemonized container when threaded"); ERROR("Cannot start non-daemonized container when threaded");
free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_free_handler(handler);
return false; return false;
} }
...@@ -942,15 +949,15 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -942,15 +949,15 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
if (conf->monitor_unshare) { if (conf->monitor_unshare) {
if (unshare(CLONE_NEWNS)) { if (unshare(CLONE_NEWNS)) {
SYSERROR("failed to unshare mount namespace"); SYSERROR("failed to unshare mount namespace");
free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_free_handler(handler);
return false; ret = 1;
goto out;
} }
if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL)) { if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL)) {
SYSERROR("Failed to make / rslave at startup"); SYSERROR("Failed to make / rslave at startup");
free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_free_handler(handler);
return false; ret = 1;
goto out;
} }
} }
...@@ -958,8 +965,10 @@ reboot: ...@@ -958,8 +965,10 @@ reboot:
if (conf->reboot == 2) { if (conf->reboot == 2) {
/* initialize handler */ /* initialize handler */
handler = lxc_init_handler(c->name, conf, c->config_path, daemonize); handler = lxc_init_handler(c->name, conf, c->config_path, daemonize);
if (!handler) if (!handler) {
ret = 1;
goto out; goto out;
}
} }
if (lxc_check_inherited(conf, daemonize, if (lxc_check_inherited(conf, daemonize,
......
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