Re: [PATCH 1/4] builtin-clone: fix a memory leak in cmd_clone()

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

Re: [PATCH 1/4] builtin-clone: fix a memory leak in cmd_clone()

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:41

Miklos Vajna [off-list ref] writes:
quoted hunk
Signed-off-by: Miklos Vajna <redacted>
---
 builtin-clone.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index 8e1a1d3..da21cab 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -516,6 +516,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		refs = transport_get_remote_refs(transport);
 		transport_fetch_refs(transport, refs);
 	}
+	free(dir);
 
 	clear_extra_refs();
Can't this be done much earlier?  This variable can potentially be
assigned to work_tree, but after we set up the atexit handler neither dir
nor work_tree are not used (it is a bit hard to see as this function
itself is a bit too big to be maintainable).

Re: [PATCH 1/4] builtin-clone: fix a memory leak in cmd_clone()

From: Miklos Vajna <hidden>
Date: 2016-06-15 22:45:41

On Sun, Nov 23, 2008 at 07:51:36PM -0800, Junio C Hamano [off-list ref] wrote:
Can't this be done much earlier?  This variable can potentially be
assigned to work_tree, but after we set up the atexit handler neither dir
nor work_tree are not used (it is a bit hard to see as this function
itself is a bit too big to be maintainable).
Hm, reading the code again I think you should just drop 1/4.

work_tree is a pointer to dir, and junk_work_tree is a pointer to
work_tree. junk_work_tree is used in the signal handler, so it has to be
allocated during the whole clone.

I guess it was just an accident that my patch passed the tests.

Sorry for the mistake.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help