Skip to content

Commit fe583c6

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53f9a3e commit fe583c6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/remote.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static int read_remote_branches(const char *refname,
565565

566566
strbuf_addf(&buf, "refs/remotes/%s/", rename->old_name);
567567
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);
569569
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
570570
NULL, &flag);
571571
if (symref && (flag & REF_ISSYMREF))
@@ -611,7 +611,7 @@ static int mv(int argc, const char **argv)
611611
struct remote *oldremote, *newremote;
612612
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT,
613613
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;
615615
struct rename_info rename;
616616
int i, refspec_updated = 0;
617617

@@ -733,6 +733,7 @@ static int mv(int argc, const char **argv)
733733
if (create_symref(buf.buf, buf2.buf, buf3.buf))
734734
die(_("creating '%s' failed"), buf.buf);
735735
}
736+
string_list_clear(&remote_branches, 1);
736737
return 0;
737738
}
738739

0 commit comments

Comments
 (0)