Skip to content

Commit 94c6285

Browse files
peffgitster
authored andcommitted
http-push: free transfer_request strbuf
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d3c71d commit 94c6285

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

http-push.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static void start_put(struct transfer_request *request)
375375
/* Set it up */
376376
git_deflate_init(&stream, zlib_compression_level);
377377
size = git_deflate_bound(&stream, len + hdrlen);
378-
strbuf_init(&request->buffer.buf, size);
378+
strbuf_grow(&request->buffer.buf, size);
379379
request->buffer.posn = 0;
380380

381381
/* Compress it */
@@ -515,6 +515,7 @@ static void release_request(struct transfer_request *request)
515515

516516
free(request->url);
517517
free(request->dest);
518+
strbuf_release(&request->buffer.buf);
518519
free(request);
519520
}
520521

@@ -655,6 +656,7 @@ static void add_fetch_request(struct object *obj)
655656
CALLOC_ARRAY(request, 1);
656657
request->obj = obj;
657658
request->state = NEED_FETCH;
659+
strbuf_init(&request->buffer.buf, 0);
658660
request->next = request_queue_head;
659661
request_queue_head = request;
660662

@@ -689,6 +691,7 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
689691
request->obj = obj;
690692
request->lock = lock;
691693
request->state = NEED_PUSH;
694+
strbuf_init(&request->buffer.buf, 0);
692695
request->next = request_queue_head;
693696
request_queue_head = request;
694697

0 commit comments

Comments
 (0)