net/failsafe: fix missing pclose after popen
When there is no preferred device, failsafe will always
try to scan for preferred device. And if there is no device
found with the exec option, popen() will get an empty output.
In this case, it was forgotten to close the file descriptor.
It is fixed by closing the file descriptor even if the output is empty.
Coverity issue: 158633
Fixes: a0194d8281
("net/failsafe: add flexible device definition")
Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
This commit is contained in:
parent
c1f7b53c83
commit
35ffe42081
@ -115,7 +115,7 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
|
||||
char output[DEVARGS_MAXLEN + 1];
|
||||
size_t len;
|
||||
int old_err;
|
||||
int ret;
|
||||
int ret, pclose_ret;
|
||||
|
||||
RTE_ASSERT(cmdline != NULL || sdev->cmdline != NULL);
|
||||
if (sdev->cmdline == NULL) {
|
||||
@ -145,7 +145,8 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
|
||||
/* We only read one line */
|
||||
if (fgets(output, sizeof(output) - 1, fp) == NULL) {
|
||||
DEBUG("Could not read command output");
|
||||
return -ENODEV;
|
||||
ret = -ENODEV;
|
||||
goto ret_pclose;
|
||||
}
|
||||
fs_sanitize_cmdline(output);
|
||||
ret = fs_parse_device(sdev, output);
|
||||
@ -154,12 +155,12 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
|
||||
goto ret_pclose;
|
||||
}
|
||||
ret_pclose:
|
||||
ret = pclose(fp);
|
||||
if (ret) {
|
||||
ret = errno;
|
||||
pclose_ret = pclose(fp);
|
||||
if (pclose_ret) {
|
||||
pclose_ret = errno;
|
||||
ERROR("pclose: %s", strerror(errno));
|
||||
errno = old_err;
|
||||
return ret;
|
||||
return pclose_ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user