]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_start: free the conf if starting the container fails
authorWeng Meiling <wengmeiling.weng@huawei.com>
Fri, 3 May 2013 03:02:48 +0000 (11:02 +0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 3 May 2013 17:26:11 +0000 (12:26 -0500)
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 <wengmeiling.weng@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_start.c

index d923a7eb5fbadf8dcac9e2d9209b45e67a61e349..12aacb8cc54d082fbaa066d98f17f1cc0e3b0d1d 100644 (file)
@@ -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;
 }