@matheusbsbs / matheus-bagliano / commits / 53f313897e
Fork 0

http-fetch: Abort requests for objects which arrived in packs

In fetch_object, there's a call to release an object request if the object mysteriously arrived, say in a pack. Unfortunately, the fetch attempt for this object might already be in progress, and we'll leak the descriptor. Instead, try to tidy away the request. Signed-off-by: Mark Wooding <mdw@distorted.org.uk> Signed-off-by: Junio C Hamano <junkio@cox.net>

Mark Wooding committed Feb 7, 2006 at 10:07 UTC 53f313897e37f25e1411a6a7cfa328d642847345
3 files changed +33 -2
http-fetch.c
+15 -1
@@ -773,6 +773,20 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
773 return 0;
774 }
775
776 +static void abort_object_request(struct object_request *obj_req)
777 +{
778 + if (obj_req->local >= 0) {
779 + close(obj_req->local);
780 + obj_req->local = -1;
781 + }
782 + unlink(obj_req->tmpfile);
783 + if (obj_req->slot) {
784 + release_active_slot(obj_req->slot);
785 + obj_req->slot = NULL;
786 + }
787 + release_object_request(obj_req);
788 +}
789 +
790 static int fetch_object(struct alt_base *repo, unsigned char *sha1)
791 {
792 char *hex = sha1_to_hex(sha1);
@@ -785,7 +799,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
799 return error("Couldn't find request for %s in the queue", hex);
800
801 if (has_sha1_file(obj_req->sha1)) {
788 - release_object_request(obj_req);
802 + abort_object_request(obj_req);
803 return 0;
804 }
805
http.c
+17 -1
@@ -420,10 +420,26 @@ void run_active_slot(struct active_request_slot *slot)
420 #endif
421 }
422
423 -static void finish_active_slot(struct active_request_slot *slot)
423 +static void closedown_active_slot(struct active_request_slot *slot)
424 {
425 active_requests--;
426 slot->in_use = 0;
427 +}
428 +
429 +void release_active_slot(struct active_request_slot *slot)
430 +{
431 + closedown_active_slot(slot);
432 + if (slot->curl) {
433 + curl_multi_remove_handle(curlm, slot->curl);
434 + curl_easy_cleanup(slot->curl);
435 + slot->curl = NULL;
436 + }
437 + fill_active_slots();
438 +}
439 +
440 +static void finish_active_slot(struct active_request_slot *slot)
441 +{
442 + closedown_active_slot(slot);
443 curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
444
445 /* Store slot results so they can be read after the slot is reused */
http.h
+1
@@ -61,6 +61,7 @@ extern struct active_request_slot *get_active_slot(void);
61 extern int start_active_slot(struct active_request_slot *slot);
62 extern void run_active_slot(struct active_request_slot *slot);
63 extern void finish_all_active_slots(void);
64 +extern void release_active_slot(struct active_request_slot *slot);
65
66 #ifdef USE_CURL_MULTI
67 extern void fill_active_slots(void);