[PATCH] Fix resource leaks in wrapper.c

Subsystems: the rest

DORMANTno replies

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH] Fix resource leaks in wrapper.c

From: Laszlo Papp <hidden>
Date: 2016-06-15 22:47:37

Fix the following issues with the desired close tags:

[wrapper.c:276]: (error) Resource leak: fd
[wrapper.c:291]: (error) Resource leak: fd

Signed-off-by: Laszlo Papp <redacted>
---
 wrapper.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/wrapper.c b/wrapper.c
index c9be140..76ecf0a 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -266,7 +266,7 @@ int odb_mkstemp(char *template, size_t limit, const char *pattern)
 	fd = mkstemp(template);
 	if (0 <= fd)
 		return fd;
-
+	close(fd);
 	/* slow path */
 	/* some mkstemp implementations erase template on failure */
 	snprintf(template, limit, "%s/%s",
@@ -284,7 +284,7 @@ int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)
 	fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
 	if (0 <= fd)
 		return fd;
-
+	close(fd);
 	/* slow path */
 	safe_create_leading_directories(name);
 	return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
-- 
1.6.5

Re: [PATCH] Fix resource leaks in wrapper.c

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:47:37

Laszlo Papp schrieb:
quoted hunk
@@ -266,7 +266,7 @@ int odb_mkstemp(char *template, size_t limit, const char *pattern)
 	fd = mkstemp(template);
 	if (0 <= fd)
 		return fd;
-
+	close(fd);
Sorry, where is here a resource leak? You are "closing" something that was
never opened because fd is less than zero.

Ditto for the other case.

-- Hannes

Re: [PATCH] Fix resource leaks in wrapper.c

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:47:37

Johannes Sixt venit, vidit, dixit 27.10.2009 08:13:
Laszlo Papp schrieb:
quoted
@@ -266,7 +266,7 @@ int odb_mkstemp(char *template, size_t limit, const char *pattern)
 	fd = mkstemp(template);
 	if (0 <= fd)
 		return fd;
-
+	close(fd);
Sorry, where is here a resource leak? You are "closing" something that was
never opened because fd is less than zero.

Ditto for the other case.
I guess it's about silencing some challenged code analysis tool. I
recall that last time we had something like this we decided that coders
are smarter than tools... and also that clean up like this (for real
leaks) would be something for libgit.

Michael
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help