Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 28b3563

Browse files
peffgitster
authored andcommitted
free ref string returned by dwim_ref
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d51428b commit 28b3563

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

builtin/rev-parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
150150
error("refname '%s' is ambiguous", name);
151151
break;
152152
}
153+
free(full);
153154
} else {
154155
show_with_type(type, name);
155156
}

builtin/show-branch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
779779
sprintf(nth_desc, "%s@{%d}", *av, base+i);
780780
append_ref(nth_desc, sha1, 1);
781781
}
782+
free(ref);
782783
}
783784
else if (all_heads + all_remotes)
784785
snarf_refs(all_heads, all_remotes);

sha1_name.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
540540
char *tmp = xstrndup(str + at + 2, reflog_len);
541541
at_time = approxidate_careful(tmp, &errors);
542542
free(tmp);
543-
if (errors)
543+
if (errors) {
544+
free(real_ref);
544545
return -1;
546+
}
545547
}
546548
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
547549
&co_time, &co_tz, &co_cnt)) {

0 commit comments

Comments
 (0)