]> git.ipfire.org Git - thirdparty/git.git/commitdiff
free ref string returned by dwim_ref
authorJeff King <peff@peff.net>
Thu, 24 Jul 2014 04:41:11 +0000 (00:41 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 24 Jul 2014 20:57:49 +0000 (13:57 -0700)
A call to "dwim_ref(name, len, flags, &ref)" will allocate a
new string in "ref" to return the exact ref we found. We do
not consistently free it in all code paths, leading to small
leaks. The worst is in get_sha1_basic, which may be called
many times (e.g., by "cat-file --batch"), though it is
relatively unlikely, as it only triggers on a bogus reflog
specification.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rev-parse.c
builtin/show-branch.c
sha1_name.c

index 1a6122d3ae29609c30c26959fbb1ff799e13a4b2..0bce2a63d44028385db60c69793b9a6bbf4634cd 100644 (file)
@@ -150,6 +150,7 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
                                error("refname '%s' is ambiguous", name);
                                break;
                        }
+                       free(full);
                } else {
                        show_with_type(type, name);
                }
index d87317290c0bbfffb7ac66fb7cff5c608f092d93..b29309019bd3e332b3db458aa14f341bd0c82f58 100644 (file)
@@ -779,6 +779,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        sprintf(nth_desc, "%s@{%d}", *av, base+i);
                        append_ref(nth_desc, sha1, 1);
                }
+               free(ref);
        }
        else if (all_heads + all_remotes)
                snarf_refs(all_heads, all_remotes);
index 2b6322fad064845f4c782286fe9764f6b958f30d..cc3941eb084863045e3af5de78d685465c26102d 100644 (file)
@@ -540,8 +540,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
                        char *tmp = xstrndup(str + at + 2, reflog_len);
                        at_time = approxidate_careful(tmp, &errors);
                        free(tmp);
-                       if (errors)
+                       if (errors) {
+                               free(real_ref);
                                return -1;
+                       }
                }
                if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
                                &co_time, &co_tz, &co_cnt)) {