git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix resource leaks in wrapper.c
@ 2009-10-27  3:53 Laszlo Papp
  2009-10-27  7:13 ` Johannes Sixt
  0 siblings, 1 reply; 4+ messages in thread
From: Laszlo Papp @ 2009-10-27  3:53 UTC (permalink / raw)
  To: git; +Cc: Laszlo Papp

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 <djszapi@archlinux.us>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix resource leaks in wrapper.c
  2009-10-27  3:53 [PATCH] Fix resource leaks in wrapper.c Laszlo Papp
@ 2009-10-27  7:13 ` Johannes Sixt
  2009-10-27  8:26   ` Michael J Gruber
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2009-10-27  7:13 UTC (permalink / raw)
  To: Laszlo Papp; +Cc: git, Laszlo Papp

Laszlo Papp schrieb:
> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix resource leaks in wrapper.c
  2009-10-27  7:13 ` Johannes Sixt
@ 2009-10-27  8:26   ` Michael J Gruber
       [not found]     ` <a362e8010910270335g106024e6if3f016c271ab55d6@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Michael J Gruber @ 2009-10-27  8:26 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Laszlo Papp, git, Laszlo Papp

Johannes Sixt venit, vidit, dixit 27.10.2009 08:13:
> Laszlo Papp schrieb:
>> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix resource leaks in wrapper.c
       [not found]     ` <a362e8010910270335g106024e6if3f016c271ab55d6@mail.gmail.com>
@ 2009-10-27 11:44       ` Michael J Gruber
  0 siblings, 0 replies; 4+ messages in thread
From: Michael J Gruber @ 2009-10-27 11:44 UTC (permalink / raw)
  To: Laszlo Papp; +Cc: Johannes Sixt, Laszlo Papp, git

Laszlo Papp venit, vidit, dixit 27.10.2009 11:35:
> 
> 
> On Tue, Oct 27, 2009 at 9:26 AM, Michael J Gruber
> <git@drmicha.warpmail.net <mailto:git@drmicha.warpmail.net>> wrote:
> 
>     Johannes Sixt venit, vidit, dixit 27.10.2009 08:13:
>     > Laszlo Papp schrieb:
>     >> @@ -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
> 
> 
> Yeah you're rights guys, sorry for my fault, this cppcheck program is
> not the best at this momment, really sorry.

No need to feel overly sorry, but in general it helps if, in a commit
message or thereabout, you say something like "cppcheck found the
following (potential) errors".

Cheers,
Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-27 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-27  3:53 [PATCH] Fix resource leaks in wrapper.c Laszlo Papp
2009-10-27  7:13 ` Johannes Sixt
2009-10-27  8:26   ` Michael J Gruber
     [not found]     ` <a362e8010910270335g106024e6if3f016c271ab55d6@mail.gmail.com>
2009-10-27 11:44       ` Michael J Gruber

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