Skip to content

Commit

Permalink
http-fetch: Abort requests for objects which arrived in packs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
distorted-mdw authored and Junio C Hamano committed Feb 7, 2006
1 parent 66f04f3 commit 53f3138
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
16 changes: 15 additions & 1 deletion http-fetch.c
Expand Up @@ -773,6 +773,20 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
return 0;
}

static void abort_object_request(struct object_request *obj_req)
{
if (obj_req->local >= 0) {
close(obj_req->local);
obj_req->local = -1;
}
unlink(obj_req->tmpfile);
if (obj_req->slot) {
release_active_slot(obj_req->slot);
obj_req->slot = NULL;
}
release_object_request(obj_req);
}

static int fetch_object(struct alt_base *repo, unsigned char *sha1)
{
char *hex = sha1_to_hex(sha1);
Expand All @@ -785,7 +799,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
return error("Couldn't find request for %s in the queue", hex);

if (has_sha1_file(obj_req->sha1)) {
release_object_request(obj_req);
abort_object_request(obj_req);
return 0;
}

Expand Down
18 changes: 17 additions & 1 deletion http.c
Expand Up @@ -420,10 +420,26 @@ void run_active_slot(struct active_request_slot *slot)
#endif
}

static void finish_active_slot(struct active_request_slot *slot)
static void closedown_active_slot(struct active_request_slot *slot)
{
active_requests--;
slot->in_use = 0;
}

void release_active_slot(struct active_request_slot *slot)
{
closedown_active_slot(slot);
if (slot->curl) {
curl_multi_remove_handle(curlm, slot->curl);
curl_easy_cleanup(slot->curl);
slot->curl = NULL;
}
fill_active_slots();
}

static void finish_active_slot(struct active_request_slot *slot)
{
closedown_active_slot(slot);
curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);

/* Store slot results so they can be read after the slot is reused */
Expand Down
1 change: 1 addition & 0 deletions http.h
Expand Up @@ -61,6 +61,7 @@ extern struct active_request_slot *get_active_slot(void);
extern int start_active_slot(struct active_request_slot *slot);
extern void run_active_slot(struct active_request_slot *slot);
extern void finish_all_active_slots(void);
extern void release_active_slot(struct active_request_slot *slot);

#ifdef USE_CURL_MULTI
extern void fill_active_slots(void);
Expand Down

0 comments on commit 53f3138

Please sign in to comment.