diff mbox

[libnl-nft] Fix file descriptor leak on error

Message ID 50D9B656.6040809@intra2net.com
State Not Applicable
Headers show

Commit Message

Thomas Jarosch Dec. 25, 2012, 2:21 p.m. UTC
Detected by cppcheck

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

Comments

Patrick McHardy Dec. 27, 2012, 6:23 a.m. UTC | #1
On Tue, 25 Dec 2012, Thomas Jarosch wrote:

> Detected by cppcheck

Same question here.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thomas Jarosch Dec. 27, 2012, 9:49 a.m. UTC | #2
On Thursday, 27. December 2012 07:23:35 Patrick McHardy wrote:
> On Tue, 25 Dec 2012, Thomas Jarosch wrote:
> > Detected by cppcheck
> 
> Same question here.

I've submitted the patch to upstream. Thanks (also to Pablo).

Thomas

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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);