From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH] net/failsafe: fix resource leak on parse error
Date: Thu, 3 Aug 2017 14:34:00 +0200 [thread overview]
Message-ID: <6ed752048278cd6fcb1757ca305f5c6e0c86d2d4.1501763600.git.gaetan.rivet@6wind.com> (raw)
If fgets fails, the handle fp is not properly closed.
Coverity issue: 158633
Fixes: a0194d828100 ("net/failsafe: add flexible device definition")
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
drivers/net/failsafe/failsafe_args.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
index 932e371..3f6430b 100644
--- a/drivers/net/failsafe/failsafe_args.c
+++ b/drivers/net/failsafe/failsafe_args.c
@@ -145,22 +145,20 @@ 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);
- if (ret) {
+ if (ret)
ERROR("Parsing device '%s' failed", output);
- goto ret_pclose;
- }
ret_pclose:
- ret = pclose(fp);
- if (ret) {
- ret = errno;
+ if (pclose(fp)) {
+ if (ret == 0)
+ ret = errno;
ERROR("pclose: %s", strerror(errno));
- errno = old_err;
- return ret;
}
+ errno = old_err;
return ret;
}
--
2.1.4
next reply other threads:[~2017-08-03 12:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 12:34 Gaetan Rivet [this message]
2017-08-03 13:59 ` Gaëtan Rivet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6ed752048278cd6fcb1757ca305f5c6e0c86d2d4.1501763600.git.gaetan.rivet@6wind.com \
--to=gaetan.rivet@6wind.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).