]> git.ipfire.org Git - thirdparty/git.git/commitdiff
checkout: fix leak of non-existent branch names
authorJeff King <peff@peff.net>
Fri, 14 Aug 2020 16:14:53 +0000 (12:14 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Aug 2020 17:52:04 +0000 (10:52 -0700)
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>
builtin/checkout.c

index af849c644fec1852845b1dfdb6ce8daa903e0fb5..ef85fd48adeccdf0e0909847e41bd0f2ea8b6101 100644 (file)
@@ -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) {