Skip to content

Commit 88682b0

Browse files
avargitster
authored andcommitted
protocol-caps.c: fix memory leak in send_info()
Fix a memory leak in a2ba162 (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 a2ba162. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Acked-by: Bruno Albuquerque <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d94f9b8 commit 88682b0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

protocol-caps.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ static void send_info(struct repository *r, struct packet_writer *writer,
6969
}
7070
}
7171

72-
packet_writer_write(writer, "%s",
73-
strbuf_detach(&send_buffer, NULL));
72+
packet_writer_write(writer, "%s", send_buffer.buf);
73+
strbuf_reset(&send_buffer);
7474
}
75+
strbuf_release(&send_buffer);
7576
}
7677

7778
int cap_object_info(struct repository *r, struct strvec *keys,

0 commit comments

Comments
 (0)