When we issue a PUT, we initialize and fill a strbuf embedded in the transfer_request struct. But we never release this buffer, causing a leak. We can fix this by adding a strbuf_release() call to release_request(). If we stopped there, then non-PUT requests would try to release a zero-initialized strbuf. This works OK in practice, but we should try to follow the strbuf API more closely. So instead, we'll always initialize the strbuf when we create the transfer_request struct. That in turn means switching the strbuf_init() call in start_put() to a simple strbuf_grow(). This leak is triggered in t5540. Signed-off-by: Jeff King <peff@xxxxxxxx> --- http-push.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/http-push.c b/http-push.c index 9aa4d11ccd..8acdb3f265 100644 --- a/http-push.c +++ b/http-push.c @@ -375,7 +375,7 @@ static void start_put(struct transfer_request *request) /* Set it up */ git_deflate_init(&stream, zlib_compression_level); size = git_deflate_bound(&stream, len + hdrlen); - strbuf_init(&request->buffer.buf, size); + strbuf_grow(&request->buffer.buf, size); request->buffer.posn = 0; /* Compress it */ @@ -515,6 +515,7 @@ static void release_request(struct transfer_request *request) free(request->url); free(request->dest); + strbuf_release(&request->buffer.buf); free(request); } @@ -655,6 +656,7 @@ static void add_fetch_request(struct object *obj) CALLOC_ARRAY(request, 1); request->obj = obj; request->state = NEED_FETCH; + strbuf_init(&request->buffer.buf, 0); request->next = request_queue_head; request_queue_head = request; @@ -689,6 +691,7 @@ static int add_send_request(struct object *obj, struct remote_lock *lock) request->obj = obj; request->lock = lock; request->state = NEED_PUSH; + strbuf_init(&request->buffer.buf, 0); request->next = request_queue_head; request_queue_head = request; -- 2.46.2.1011.gf1f9323e02