char title[2048];
pid_t pid = fork();
- if (pid < 0)
+ if (pid < 0) {
+ lxc_free_handler(handler);
return false;
+ }
if (pid != 0) {
/* Set to NULL because we don't want father unlink
} else {
if (!am_single_threaded()) {
ERROR("Cannot start non-daemonized container when threaded");
+ lxc_free_handler(handler);
return false;
}
}
if (pid_fp == NULL) {
SYSERROR("Failed to create pidfile '%s' for '%s'",
c->pidfile, c->name);
+ lxc_free_handler(handler);
if (daemonize)
exit(1);
return false;
SYSERROR("Failed to write '%s'", c->pidfile);
fclose(pid_fp);
pid_fp = NULL;
+ lxc_free_handler(handler);
if (daemonize)
exit(1);
return false;
if (conf->monitor_unshare) {
if (unshare(CLONE_NEWNS)) {
SYSERROR("failed to unshare mount namespace");
+ lxc_free_handler(handler);
return false;
}
if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL)) {
SYSERROR("Failed to make / rslave at startup");
+ lxc_free_handler(handler);
return false;
}
}
if (lxc_check_inherited(conf, daemonize, handler->conf->maincmd_fd)) {
ERROR("Inherited fds found");
+ lxc_free_handler(handler);
ret = 1;
goto out;
}
return -1;
}
+void lxc_free_handler(struct lxc_handler *handler)
+{
+ if (handler->conf && handler->conf->maincmd_fd)
+ close(handler->conf->maincmd_fd);
+
+ if (handler->name)
+ free(handler->name);
+
+ handler->conf = NULL;
+ free(handler);
+}
+
struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
const char *lxcpath)
{
handler->name = strdup(name);
if (!handler->name) {
ERROR("failed to allocate memory");
- goto do_partial_cleanup;
+ goto on_error;
}
if (lxc_cmd_init(name, handler, lxcpath)) {
ERROR("failed to set up command socket");
- goto do_full_cleanup;
+ goto on_error;
}
TRACE("unix domain socket %d for command server is ready",
return handler;
-do_full_cleanup:
- free(handler->name);
-
-do_partial_cleanup:
- free(handler);
+on_error:
+ lxc_free_handler(handler);
return NULL;
}
extern struct lxc_handler *lxc_init_handler(const char *name,
struct lxc_conf *conf,
const char *lxcpath);
+extern void lxc_free_handler(struct lxc_handler *handler);
extern int lxc_init(const char *name, struct lxc_handler *handler);
extern void lxc_fini(const char *name, struct lxc_handler *handler);