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 <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 8, 2017 at 18:29 UTC
176cb979fe7c1cf6b789c9263ca20312385c1f31
1 file changed
+5
-2
transport-helper.c
+5
-2
@@ -881,7 +881,8 @@ static int push_refs_with_push(struct transport *transport,
881
struct strbuf cas = STRBUF_INIT;
882
strbuf_addf(&cas, "%s:%s",
883
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));
886
}
887
}
888
if (buf.len == 0) {
@@ -896,6 +897,7 @@ static int push_refs_with_push(struct transport *transport,
897
strbuf_addch(&buf, '\n');
898
sendline(data, &buf);
899
strbuf_release(&buf);
900
+ string_list_clear(&cas_options, 0);
901
902
return push_update_refs_status(data, remote_refs, flags);
903
}
@@ -929,7 +931,8 @@ static int push_refs_with_export(struct transport *transport,
931
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
932
if (private && !get_oid(private, &oid)) {
933
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));
936
oidcpy(&ref->old_oid, &oid);
937
}
938
free(private);