From 28b3563241ac13733781fb0bada37f776a39f43d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 24 Jul 2014 00:41:11 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- sha1_name.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sha1_name.c') diff --git a/sha1_name.c b/sha1_name.c index 2b6322fad..cc3941eb0 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -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)) { -- cgit v1.2.1