]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Allocate cmd string with alloca instead of malloc, close popen handle if fgets fails.
authorSidnei da Silva <sidnei.da.silva@canonical.com>
Fri, 18 Oct 2013 19:35:55 +0000 (16:35 -0300)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 18 Oct 2013 19:43:03 +0000 (14:43 -0500)
src/lxc/bdev.c

index bc8ec61a4daa8c88ed9140c86e220923e6229a29..39b17116f5a4eb8d87f6654bf21faa4811461edf 100644 (file)
@@ -865,9 +865,7 @@ static int lvm_is_thin_volume(const char *path)
        const char *lvscmd = "lvs --unbuffered --noheadings -o lv_attr %s 2>/dev/null";
 
        len = strlen(lvscmd) + strlen(path) - 1;
-       cmd = malloc(len);
-       if (!cmd)
-               return -1;
+       cmd = alloca(len);
 
        ret = snprintf(cmd, len, lvscmd, path);
        if (ret < 0 || ret >= len)
@@ -882,8 +880,12 @@ static int lvm_is_thin_volume(const char *path)
                return -1;
        }
 
-       if (fgets(output, 12, f) == NULL)
+       if (fgets(output, 12, f) == NULL) {
+               process_lock();
+               (void) pclose(f);
+               process_unlock();
                return -1;
+       }
 
        process_lock();
        ret = pclose(f);