remote: clear string_list after use in mv()

Switch to the _DUP variant of string_list for remote_branches to allow string_list_clear() to release the allocated memory at the end, and actually call that function. Free the util pointer as well; it is allocated in read_remote_branches(). NB: This string_list is empty until read_remote_branches() is called via for_each_ref(), so there is no need to clean it up when returning before that point. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 1, 2018 at 12:19 UTC fe583c6c7a6726452aac87a14afa5a0bf9647d8f
1 file changed +3 -2
builtin/remote.c
+3 -2
@@ -565,7 +565,7 @@ static int read_remote_branches(const char *refname,
565
566 strbuf_addf(&buf, "refs/remotes/%s/", rename->old_name);
567 if (starts_with(refname, buf.buf)) {
568 - item = string_list_append(rename->remote_branches, xstrdup(refname));
568 + item = string_list_append(rename->remote_branches, refname);
569 symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
570 NULL, &flag);
571 if (symref && (flag & REF_ISSYMREF))
@@ -611,7 +611,7 @@ static int mv(int argc, const char **argv)
611 struct remote *oldremote, *newremote;
612 struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT,
613 old_remote_context = STRBUF_INIT;
614 - struct string_list remote_branches = STRING_LIST_INIT_NODUP;
614 + struct string_list remote_branches = STRING_LIST_INIT_DUP;
615 struct rename_info rename;
616 int i, refspec_updated = 0;
617
@@ -733,6 +733,7 @@ static int mv(int argc, const char **argv)
733 if (create_symref(buf.buf, buf2.buf, buf3.buf))
734 die(_("creating '%s' failed"), buf.buf);
735 }
736 + string_list_clear(&remote_branches, 1);
737 return 0;
738 }
739