Commit 2d4bcb96 by Weng Meiling Committed by Serge Hallyn

lxc_start: free the conf if starting the container fails

When running lxc-start command with valgrind, it reports a memory leak error. When lxc-start command fails, the conf which is from malloc has not been released. This patch fix the problem. Signed-off-by: 's avatarWeng Meiling <wengmeiling.weng@huawei.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent fc7e8864
......@@ -196,25 +196,25 @@ int main(int argc, char *argv[])
if (rcfile && lxc_config_read(rcfile, conf)) {
ERROR("failed to read configuration file");
return err;
goto out;
}
if (lxc_config_define_load(&defines, conf))
return err;
goto out;
if (!rcfile && !strcmp("/sbin/init", args[0])) {
ERROR("no configuration file for '/sbin/init' (may crash the host)");
return err;
goto out;
}
if (ensure_path(&conf->console.path, my_args.console) < 0) {
ERROR("failed to ensure console path '%s'", my_args.console);
return err;
goto out;
}
if (ensure_path(&conf->console.log_path, my_args.console_log) < 0) {
ERROR("failed to ensure console log '%s'", my_args.console_log);
return err;
goto out;
}
if (my_args.pidfile != NULL) {
......@@ -222,7 +222,7 @@ int main(int argc, char *argv[])
if (pid_fp == NULL) {
SYSERROR("failed to create pidfile '%s' for '%s'",
my_args.pidfile, my_args.name);
return err;
goto out;
}
}
......@@ -232,19 +232,19 @@ int main(int argc, char *argv[])
if (!lxc_caps_check()) {
ERROR("Not running with sufficient privilege");
return err;
goto out;
}
if (daemon(0, 0)) {
SYSERROR("failed to daemonize '%s'", my_args.name);
return err;
goto out;
}
}
if (pid_fp != NULL) {
if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
SYSERROR("failed to write '%s'", my_args.pidfile);
return err;
goto out;
}
fclose(pid_fp);
}
......@@ -267,7 +267,8 @@ int main(int argc, char *argv[])
if (my_args.pidfile)
unlink(my_args.pidfile);
out:
lxc_conf_free(conf);
return err;
}
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