netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Jarosch <thomas.jarosch@intra2net.com>
To: Patrick McHardy <kaber@trash.net>
Cc: netfilter-devel@vger.kernel.org
Subject: [libnl-nft PATCH] Fix file descriptor leak on error
Date: Tue, 25 Dec 2012 15:21:10 +0100	[thread overview]
Message-ID: <50D9B656.6040809@intra2net.com> (raw)

Detected by cppcheck

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
---
 lib/utils.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/utils.c b/lib/utils.c
index 4007bee..50ca6d9 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -60,24 +60,32 @@ int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *))
 			continue;
 
 		num = strtol(buf, &end, 0);
-		if (end == buf)
+		if (end == buf) {
+			fclose(fd);
 			return -NLE_INVAL;
+		}
 
-		if (num == LONG_MIN || num == LONG_MAX)
+		if (num == LONG_MIN || num == LONG_MAX) {
+			fclose(fd);
 			return -NLE_RANGE;
+		}
 
 		while (*end == ' ' || *end == '\t')
 			end++;
 
 		goodlen = strcspn(end, "#\r\n\t ");
-		if (goodlen == 0)
+		if (goodlen == 0) {
+			fclose(fd);
 			return -NLE_INVAL;
+		}
 
 		end[goodlen] = '\0';
 
 		err = cb(num, end);
-		if (err < 0)
+		if (err < 0) {
+			fclose(fd);
 			return err;
+		}
 	}
 
 	fclose(fd);
-- 
1.7.11.7


             reply	other threads:[~2012-12-25 14:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-25 14:21 Thomas Jarosch [this message]
2012-12-27  6:23 ` [libnl-nft PATCH] Fix file descriptor leak on error Patrick McHardy
2012-12-27  9:49   ` Thomas Jarosch

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=50D9B656.6040809@intra2net.com \
    --to=thomas.jarosch@intra2net.com \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.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).