git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] builtin/checkout.c: don't leak memory in check_tracking_name
@ 2013-06-18  1:40 Brandon Casey
  2013-06-18  1:40 ` [PATCH 2/2] t/t9802: explicitly name the upstream branch to use as a base Brandon Casey
  2013-06-18  6:15 ` [PATCH 1/2] builtin/checkout.c: don't leak memory in check_tracking_name Jeff King
  0 siblings, 2 replies; 5+ messages in thread
From: Brandon Casey @ 2013-06-18  1:40 UTC (permalink / raw)
  To: gitster; +Cc: git, Brandon Casey, johan

From: Brandon Casey <drafnel@gmail.com>

remote_find_tracking() populates the query struct with an allocated
string in the dst member.  So, we do not need to xstrdup() the string,
since we can transfer ownership from the query struct (which will go
out of scope at the end of this function) to our callback struct, but
we must free the string if it will not be used so we will not leak
memory.

Let's do so.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
---
 builtin/checkout.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index f5b50e5..3be0018 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -838,13 +838,16 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
 	memset(&query, 0, sizeof(struct refspec));
 	query.src = cb->src_ref;
 	if (remote_find_tracking(remote, &query) ||
-	    get_sha1(query.dst, cb->dst_sha1))
+	    get_sha1(query.dst, cb->dst_sha1)) {
+		free(query.dst);
 		return 0;
+	}
 	if (cb->dst_ref) {
+		free(query.dst);
 		cb->unique = 0;
 		return 0;
 	}
-	cb->dst_ref = xstrdup(query.dst);
+	cb->dst_ref = query.dst;
 	return 0;
 }
 
-- 
1.8.2.415.g63cec41

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

end of thread, other threads:[~2013-06-18 16:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-18  1:40 [PATCH 1/2] builtin/checkout.c: don't leak memory in check_tracking_name Brandon Casey
2013-06-18  1:40 ` [PATCH 2/2] t/t9802: explicitly name the upstream branch to use as a base Brandon Casey
2013-06-18 13:42   ` Pete Wyckoff
2013-06-18 16:17     ` Junio C Hamano
2013-06-18  6:15 ` [PATCH 1/2] builtin/checkout.c: don't leak memory in check_tracking_name Jeff King

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