summaryrefslogtreecommitdiff
path: root/builtin/checkout.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-08-14 16:14:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-14 17:52:04 (GMT)
commitc514c62a4fd8b4c4a3e2cad68fb590fce2940dc3 (patch)
tree4a91ef7bee58c8096e672f5b0281c218d53901b0 /builtin/checkout.c
parent9101c8ea2db466cce6d7d419d48e0516c6118813 (diff)
downloadgit-c514c62a4fd8b4c4a3e2cad68fb590fce2940dc3.zip
git-c514c62a4fd8b4c4a3e2cad68fb590fce2940dc3.tar.gz
git-c514c62a4fd8b4c4a3e2cad68fb590fce2940dc3.tar.bz2
checkout: fix leak of non-existent branch names
We unconditionally write a branch name into a newly allocated buffer in new_branch_info->path, via setup_branch_path(). We then check to see if the branch exists; if not, we set that field to NULL, leaking the memory. We should take care to free() it when doing so. Signed-off-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.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index af849c6..ef85fd4 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1126,8 +1126,10 @@ static void setup_new_branch_info_and_source_tree(
if (!check_refname_format(new_branch_info->path, 0) &&
!read_ref(new_branch_info->path, &branch_rev))
oidcpy(rev, &branch_rev);
- else
+ else {
+ free((char *)new_branch_info->path);
new_branch_info->path = NULL; /* not an existing branch */
+ }
new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1);
if (!new_branch_info->commit) {