Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Casey <drafnel@gmail.com>2013-06-18 05:40:49 +0400
committerJunio C Hamano <gitster@pobox.com>2013-06-18 18:25:06 +0400
commit2c4842023205b4b2cf7eac973cd7dc2fca263327 (patch)
treeec42b961eb123b907e371bcaef61866774123f09 /builtin/checkout.c
parent77eb44b8ed601a17a5ec9b1fb8c4c53ba10aaa56 (diff)
builtin/checkout.c: don't leak memory in check_tracking_name
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> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f5b50e520f..3be0018821 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;
}