From: Weng Meiling Date: Fri, 3 May 2013 03:02:48 +0000 (+0800) Subject: lxc_start: free the conf if starting the container fails X-Git-Tag: lxc-1.0.0.alpha1~1^2~237 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d4bcb96155c0e4a5d2734017f889b993144e876;p=thirdparty%2Flxc.git 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: Weng Meiling Signed-off-by: Serge Hallyn --- diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c index d923a7eb5..12aacb8cc 100644 --- a/src/lxc/lxc_start.c +++ b/src/lxc/lxc_start.c @@ -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; }