Commit 55a204f9 by Sidnei da Silva Committed by Serge Hallyn

Allocate cmd string with alloca instead of malloc, close popen handle if fgets fails.

parent 62c70ee2
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment