]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: fix resource leak [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 15 May 2019 14:01:32 +0000 (16:01 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 May 2019 14:01:32 +0000 (16:01 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/path.c

index 6922e27704ccfec2a3ec84020fdd5c0345bdb23b..05b608e573b48ba47cd1d64c0774fdbd8ffb64b9 100644 (file)
@@ -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';