Skip to content

Commit 176cb97

Browse files
rscharfegitster
authored andcommitted
transport-helper: plug strbuf and string_list leaks
Transfer ownership of detached strbufs to string_lists of the duplicating variety by calling string_list_append_nodup() instead of string_list_append() to avoid duplicating and then leaking the buffer. While at it make sure to release the string_list when done; push_refs_with_export() already does that. Reported-by: Jeff King <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3013dff commit 176cb97

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

transport-helper.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ static int push_refs_with_push(struct transport *transport,
881881
struct strbuf cas = STRBUF_INIT;
882882
strbuf_addf(&cas, "%s:%s",
883883
ref->name, oid_to_hex(&ref->old_oid_expect));
884-
string_list_append(&cas_options, strbuf_detach(&cas, NULL));
884+
string_list_append_nodup(&cas_options,
885+
strbuf_detach(&cas, NULL));
885886
}
886887
}
887888
if (buf.len == 0) {
@@ -896,6 +897,7 @@ static int push_refs_with_push(struct transport *transport,
896897
strbuf_addch(&buf, '\n');
897898
sendline(data, &buf);
898899
strbuf_release(&buf);
900+
string_list_clear(&cas_options, 0);
899901

900902
return push_update_refs_status(data, remote_refs, flags);
901903
}
@@ -929,7 +931,8 @@ static int push_refs_with_export(struct transport *transport,
929931
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
930932
if (private && !get_oid(private, &oid)) {
931933
strbuf_addf(&buf, "^%s", private);
932-
string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
934+
string_list_append_nodup(&revlist_args,
935+
strbuf_detach(&buf, NULL));
933936
oidcpy(&ref->old_oid, &oid);
934937
}
935938
free(private);

0 commit comments

Comments
 (0)