http-push: free xml_ctx.cdata after use
When we ask libexpat to parse XML data, we sometimes set xml_cdata as a CharacterDataHandler callback. This fills in an allocated string in the xml_ctx struct which we never free, causing a leak. I won't pretend to understand the purpose of the field, but it looks like it is used by other callbacks during the parse. At any rate, we never look at it again after XML_Parse() returns, so we should be OK to free() it then. This fixes several leaks triggered by t5540. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 24, 2024 at 18:09 UTC
3245a2ade5ee0ff3e5fad7bd96ad0a630c590e82
1 file changed
+2
http-push.c
+2
@@ -913,6 +913,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
913
result = XML_Parse(parser, in_buffer.buf,
914
in_buffer.len, 1);
915
free(ctx.name);
916
+ free(ctx.cdata);
917
if (result != XML_STATUS_OK) {
918
fprintf(stderr, "XML error: %s\n",
919
XML_ErrorString(
@@ -1170,6 +1171,7 @@ static void remote_ls(const char *path, int flags,
1171
result = XML_Parse(parser, in_buffer.buf,
1172
in_buffer.len, 1);
1173
free(ctx.name);
1174
+ free(ctx.cdata);
1175
1176
if (result != XML_STATUS_OK) {
1177
fprintf(stderr, "XML error: %s\n",