Skip to content

Commit 7d3c71d

Browse files
peffgitster
authored andcommitted
http-push: free transfer_request dest field
When we issue a PUT request, we store the destination in the "dest" field by detaching from a strbuf. But we never free the result, causing a leak. We can address this in the release_request() function. But note that we also need to initialize it to NULL, as most other request types do not set it at all. Curiously there are _two_ functions to initialize a transfer_request struct. Adding the initialization only to add_fetch_request() seems to be enough for t5540, but I won't pretend to understand why. Rather than just adding "request->dest = NULL" in both spots, let's zero the whole struct. That addresses this problem, as well as any future ones (and it can't possibly hurt, as by definition we'd be hitting uninitialized memory previously). This fixes several leaks noticed by t5540. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 747a710 commit 7d3c71d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

http-push.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ static void release_request(struct transfer_request *request)
514514
}
515515

516516
free(request->url);
517+
free(request->dest);
517518
free(request);
518519
}
519520

@@ -651,11 +652,8 @@ static void add_fetch_request(struct object *obj)
651652
return;
652653

653654
obj->flags |= FETCHING;
654-
request = xmalloc(sizeof(*request));
655+
CALLOC_ARRAY(request, 1);
655656
request->obj = obj;
656-
request->url = NULL;
657-
request->lock = NULL;
658-
request->headers = NULL;
659657
request->state = NEED_FETCH;
660658
request->next = request_queue_head;
661659
request_queue_head = request;
@@ -687,11 +685,9 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
687685
}
688686

689687
obj->flags |= PUSHING;
690-
request = xmalloc(sizeof(*request));
688+
CALLOC_ARRAY(request, 1);
691689
request->obj = obj;
692-
request->url = NULL;
693690
request->lock = lock;
694-
request->headers = NULL;
695691
request->state = NEED_PUSH;
696692
request->next = request_queue_head;
697693
request_queue_head = request;

0 commit comments

Comments
 (0)