lib/path: fix resource leak [coverity scan]

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-05-15 16:01:32 +02:00
parent 8083862536
commit 91bf581742
1 changed files with 5 additions and 2 deletions

View 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';