git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix memory leaks in read_tree_recursive()
@ 2005-05-04 23:19 Jonas Fonseca
  2005-05-04 23:39 ` Jonas Fonseca
  2005-05-04 23:43 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Jonas Fonseca @ 2005-05-04 23:19 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

This patch fixes memory leaks in the error path of
read_tree_recursive().

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

--- 571c0f4599fbeefd995bbc24480add1575c36c94/tree.c  (mode:100644 sha1:4a26603f6e32866c0db8a01ac1c228be801f76c6)
+++ uncommitted/tree.c  (mode:100644)
@@ -39,14 +39,18 @@
 		if (S_ISDIR(mode)) {
 			int retval;
 			int pathlen = strlen(path);
-			char *newbase = xmalloc(baselen + 1 + pathlen);
+			char *newbase;
 			void *eltbuf;
 			char elttype[20];
 			unsigned long eltsize;
 
 			eltbuf = read_sha1_file(sha1, elttype, &eltsize);
-			if (!eltbuf || strcmp(elttype, "tree"))
+			if (!eltbuf || strcmp(elttype, "tree")) {
+				if (eltbuf) mem_free(eltbuf);
 				return -1;
+			}
+
+			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
 			memcpy(newbase + baselen, path, pathlen);
 			newbase[baselen + pathlen] = '/';

-- 
Jonas Fonseca

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

* [PATCH] Fix memory leaks in read_tree_recursive()
  2005-05-04 23:19 [PATCH] Fix memory leaks in read_tree_recursive() Jonas Fonseca
@ 2005-05-04 23:39 ` Jonas Fonseca
  2005-05-04 23:43 ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Jonas Fonseca @ 2005-05-04 23:39 UTC (permalink / raw)
  To: Linus Torvalds, git

This patch fixes memory leaks in read_tree_recursive().

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

---

Sorry, typo in the previous patch. I will try to be more careful.
This patch has already been applied to cogito.

--- 571c0f4599fbeefd995bbc24480add1575c36c94/tree.c  (mode:100644 sha1:4a26603f6e32866c0db8a01ac1c228be801f76c6)
+++ uncommitted/tree.c  (mode:100644)
@@ -39,14 +39,18 @@
 		if (S_ISDIR(mode)) {
 			int retval;
 			int pathlen = strlen(path);
-			char *newbase = xmalloc(baselen + 1 + pathlen);
+			char *newbase;
 			void *eltbuf;
 			char elttype[20];
 			unsigned long eltsize;
 
 			eltbuf = read_sha1_file(sha1, elttype, &eltsize);
-			if (!eltbuf || strcmp(elttype, "tree"))
+			if (!eltbuf || strcmp(elttype, "tree")) {
+				if (eltbuf) free(eltbuf);
 				return -1;
+			}
+
+			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
 			memcpy(newbase + baselen, path, pathlen);
 			newbase[baselen + pathlen] = '/';

-- 
Jonas Fonseca

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

* Re: [PATCH] Fix memory leaks in read_tree_recursive()
  2005-05-04 23:19 [PATCH] Fix memory leaks in read_tree_recursive() Jonas Fonseca
  2005-05-04 23:39 ` Jonas Fonseca
@ 2005-05-04 23:43 ` Junio C Hamano
  2005-05-05  0:08   ` Jonas Fonseca
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2005-05-04 23:43 UTC (permalink / raw)
  To: Jonas Fonseca; +Cc: git

>>>>> "JF" == Jonas Fonseca <fonseca@diku.dk> writes:

JF> This patch fixes memory leaks in the error path of
JF> read_tree_recursive().

The leak seems to be real but what is "mem_free"?  Has it been
compile tested?

JF> @@ -39,14 +39,18 @@
JF>  		if (S_ISDIR(mode)) {
JF>  			int retval;
 
JF> ...
JF> -			if (!eltbuf || strcmp(elttype, "tree"))
JF> +			if (!eltbuf || strcmp(elttype, "tree")) {
JF> +				if (eltbuf) mem_free(eltbuf);
JF>  				return -1;

Btw, who is putting this header in your mail?  It does not make
sense to me unless Jonas is pseudonym for Linus...

  Mail-Followup-To: Linus Torvalds <torvalds@osdl.org>, git@vger.kernel.org 



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

* Re: [PATCH] Fix memory leaks in read_tree_recursive()
  2005-05-04 23:43 ` Junio C Hamano
@ 2005-05-05  0:08   ` Jonas Fonseca
  0 siblings, 0 replies; 4+ messages in thread
From: Jonas Fonseca @ 2005-05-05  0:08 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <junkio@cox.net> wrote Wed, May 04, 2005:
> >>>>> "JF" == Jonas Fonseca <fonseca@diku.dk> writes:
> 
> JF> This patch fixes memory leaks in the error path of
> JF> read_tree_recursive().
> 
> The leak seems to be real but what is "mem_free"?

That mem_free() was a bad habbit from the project I usually work on.

> Has it been compile tested?

No, but the second patch has.

BTW, when compiling git on a FreeBSD box I get these warnings:

date.c: In function `parse_date':
date.c:414: warning: long unsigned int format, time_t arg (arg 4)
date.c:414: warning: long unsigned int format, time_t arg (arg 4)
date.c: In function `datestamp':
date.c:427: warning: long unsigned int format, time_t arg (arg 4)
date.c:427: warning: long unsigned int format, time_t arg (arg 4)
tar-tree.c: In function `write_header':
tar-tree.c:249: warning: long unsigned int format, time_t arg (arg 3)
local-pull.c: In function `fetch':
local-pull.c:73: warning: long int format, different type arg (arg 4)

because time_t is defined as int32_t.  Don't know if they are worth
fixing at this point.

> JF> @@ -39,14 +39,18 @@
> JF>  		if (S_ISDIR(mode)) {
> JF>  			int retval;
>  
> JF> ...
> JF> -			if (!eltbuf || strcmp(elttype, "tree"))
> JF> +			if (!eltbuf || strcmp(elttype, "tree")) {
> JF> +				if (eltbuf) mem_free(eltbuf);
> JF>  				return -1;
> 
> Btw, who is putting this header in your mail?  It does not make
> sense to me unless Jonas is pseudonym for Linus...
> 
>   Mail-Followup-To: Linus Torvalds <torvalds@osdl.org>, git@vger.kernel.org 

Maybe because Mutt knows I am subscribe to this mailing list and assumes
I don't want to have mail addressed directly to my email address?

I just hit 'g'.

-- 
Jonas Fonseca

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

end of thread, other threads:[~2005-05-05  0:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-04 23:19 [PATCH] Fix memory leaks in read_tree_recursive() Jonas Fonseca
2005-05-04 23:39 ` Jonas Fonseca
2005-05-04 23:43 ` Junio C Hamano
2005-05-05  0:08   ` Jonas Fonseca

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