summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2019-05-15 16:01:32 +0200
committerKarel Zak2019-05-15 16:01:32 +0200
commit91bf5817426c34ea3a3f37b291b6b1ba7fe4eb52 (patch)
treed79bde3764f79a4134c9786b6cd84d677a359b8f /lib
parentlib/path: fix possible NULL dereferencing [coverity scan] (diff)
downloadkernel-qcow2-util-linux-91bf5817426c34ea3a3f37b291b6b1ba7fe4eb52.tar.gz
kernel-qcow2-util-linux-91bf5817426c34ea3a3f37b291b6b1ba7fe4eb52.tar.xz
kernel-qcow2-util-linux-91bf5817426c34ea3a3f37b291b6b1ba7fe4eb52.zip
lib/path: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/path.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/path.c b/lib/path.c
index 6922e2770..05b608e57 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -928,6 +928,7 @@ static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, i
FILE *f;
size_t setsize, len = maxcpus * 7;
char buf[len];
+ int rc;
*set = NULL;
@@ -935,10 +936,12 @@ static int ul_path_cpuparse(struct path_cxt *pc, cpu_set_t **set, int maxcpus, i
if (!f)
return -errno;
- if (!fgets(buf, len, f))
- return -errno;
+ rc = fgets(buf, len, f) == NULL ? -errno : 0;
fclose(f);
+ if (rc)
+ return rc;
+
len = strlen(buf);
if (buf[len - 1] == '\n')
buf[len - 1] = '\0';