From 88682b016dcbdbbdebdd2efd9b7de63e4395636f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 31 Aug 2021 15:46:42 +0200 Subject: protocol-caps.c: fix memory leak in send_info() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a memory leak in a2ba162cda (object-info: support for retrieving object info, 2021-04-20) which appears to have been based on a misunderstanding of how the pkt-line.c API works. There is no need to strdup() input to packet_writer_write(), it's just a printf()-like format function. This fixes a potentially large memory leak, since the number of OID lines the "object-info" call can be arbitrarily large (or a small one if the request is small). This makes t5701-git-serve.sh pass again under SANITIZE=leak, as it did before a2ba162cda2. Signed-off-by: Ævar Arnfjörð Bjarmason Acked-by: Bruno Albuquerque Signed-off-by: Junio C Hamano --- protocol-caps.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'protocol-caps.c') diff --git a/protocol-caps.c b/protocol-caps.c index 13a9e63a04..901b6795e4 100644 --- a/protocol-caps.c +++ b/protocol-caps.c @@ -69,9 +69,10 @@ static void send_info(struct repository *r, struct packet_writer *writer, } } - packet_writer_write(writer, "%s", - strbuf_detach(&send_buffer, NULL)); + packet_writer_write(writer, "%s", send_buffer.buf); + strbuf_reset(&send_buffer); } + strbuf_release(&send_buffer); } int cap_object_info(struct repository *r, struct strvec *keys, -- cgit v1.2.3