]> git.proxmox.com Git - mirror_lxc.git/commitdiff
coverity: fix leak in error case
authorDwight Engen <dwight.engen@oracle.com>
Fri, 3 May 2013 16:04:01 +0000 (12:04 -0400)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 3 May 2013 17:26:17 +0000 (12:26 -0500)
Since lxc_execute() is available through the library and is exposed via
the API we cannot be sure the caller will immediately exit, so we should
take care to free the allocated memory.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/execute.c

index d93e8e17caf1bd96d4bc1dbeeb38bcceb32a57f8..9bf33cae661bbcdcde32e9c3e0a75dace4fb8ef3 100644 (file)
@@ -55,7 +55,7 @@ static char *choose_init(void)
        ret = snprintf(retv, PATH_MAX, LXCINITDIR "/lxc/lxc-init");
        if (ret < 0 || ret >= PATH_MAX) {
                ERROR("pathname too long");
-               return NULL;
+               goto out1;
        }
 
        ret = stat(retv, &mystat);
@@ -65,7 +65,7 @@ static char *choose_init(void)
        ret = snprintf(retv, PATH_MAX, "/usr/lib/lxc/lxc-init");
        if (ret < 0 || ret >= PATH_MAX) {
                ERROR("pathname too long");
-               return NULL;
+               goto out1;
        }
        ret = stat(retv, &mystat);
        if (ret == 0)
@@ -73,11 +73,13 @@ static char *choose_init(void)
        ret = snprintf(retv, PATH_MAX, "/sbin/lxc-init");
        if (ret < 0 || ret >= PATH_MAX) {
                ERROR("pathname too long");
-               return NULL;
+               goto out1;
        }
        ret = stat(retv, &mystat);
        if (ret == 0)
                return retv;
+out1:
+       free(retv);
        return NULL;
 }