summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-05-25 15:33:05 -0400
committerJunio C Hamano <gitster@pobox.com>2017-05-26 12:51:06 +0900
commitef4fe5617eadc24fd09ce7778b77bb87f147480c (patch)
tree83aec44a41bc665699ca91c5f4ee96ec0cdbb5c9
parent95d67879735cfecfdd85f89e59d993c5b4de8835 (diff)
downloadgit-jk/connect-symref-info-leak-fix.tar.gz
connect.c: fix leak in parse_one_symref_info()jk/connect-symref-info-leak-fix
If we successfully parse a symref value like "HEAD:refs/heads/master", we add the result to a string list. But because the string list is marked STRING_LIST_INIT_DUP, the string list code will make a copy of the string and add the copy. This patch fixes it by adding the entry with string_list_append_nodup(), which lets the string list take ownership of our newly allocated string. There are two alternatives that seem like they would work, but aren't the right solution. The first is to initialize the list with the "NODUP" initializer. That would avoid the copy, but then the string list would not realize that it owns the strings. When we eventually call string_list_clear(), it would not free the strings, causing a leak. The second option would be to use the normal string_list_append(), but free the local copy in our function. We can't do this because the local copy actually contains _two_ strings; the symref name and its target. We point to the target pointer via the "util" field, and its memory must last as long as the string list does. You may also wonder whether it's safe to ever free the local copy, since the target points into it. The answer is yes, because we duplicate it in annotaate_refs_with_symref_info before clearing the string list. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--connect.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/connect.c b/connect.c
index 8cb93b0720..8af002bf0f 100644
--- a/connect.c
+++ b/connect.c
@@ -71,7 +71,7 @@ static void parse_one_symref_info(struct string_list *symref, const char *val, i
check_refname_format(target, REFNAME_ALLOW_ONELEVEL))
/* "symref=bogus:pair */
goto reject;
- item = string_list_append(symref, sym);
+ item = string_list_append_nodup(symref, sym);
item->util = target;
return;
reject: