From: Sidnei da Silva Date: Fri, 18 Oct 2013 19:35:55 +0000 (-0300) Subject: Allocate cmd string with alloca instead of malloc, close popen handle if fgets fails. X-Git-Tag: lxc-1.0.0.alpha2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55a204f9f4696dc5fca65ddebde3568ee030246d;p=thirdparty%2Flxc.git Allocate cmd string with alloca instead of malloc, close popen handle if fgets fails. --- diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index bc8ec61a4..39b17116f 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -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);