From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] http: check curl_multi_remove_handle error code
Date: Wed, 21 Sep 2016 21:20:54 +0000 [thread overview]
Message-ID: <20160921212054.17177-1-e@80x24.org> (raw)
This should help detect bugs in future changes. While we're at
it, fix a (probably innocuous) bug in our http_cleanup function
for users of older curl.
curl_multi_remove_handle was not idempotent until curl 7.33.0
with commit 84f3b3dd448399f9548468676e1bd1475dba8de5
("curl_multi_remove_handle: allow multiple removes"),
so we track the "curlm" membership of the curl easy handle
ourselves with a new "in_multi" flag.
Tested with curl 7.26.0 and 7.38.0 on Debian 7.x (wheezy) and
Debian 8.x (jessie) respectively.
Signed-off-by: Eric Wong <e@80x24.org>
---
http.c | 12 ++++++++++--
http.h | 1 +
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/http.c b/http.c
index 82ed542..9f97749 100644
--- a/http.c
+++ b/http.c
@@ -204,7 +204,12 @@ static void finish_active_slot(struct active_request_slot *slot)
static void xmulti_remove_handle(struct active_request_slot *slot)
{
#ifdef USE_CURL_MULTI
- curl_multi_remove_handle(curlm, slot->curl);
+ CURLMcode code = curl_multi_remove_handle(curlm, slot->curl);
+
+ if (code != CURLM_OK)
+ die("curl_multi_remove_handle failed (%p): %s",
+ slot->curl, curl_multi_strerror(code));
+ slot->in_multi = 0;
#endif
}
@@ -888,7 +893,8 @@ void http_cleanup(void)
while (slot != NULL) {
struct active_request_slot *next = slot->next;
if (slot->curl != NULL) {
- xmulti_remove_handle(slot);
+ if (slot->in_multi)
+ xmulti_remove_handle(slot);
curl_easy_cleanup(slot->curl);
}
free(slot);
@@ -965,6 +971,7 @@ struct active_request_slot *get_active_slot(void)
newslot = xmalloc(sizeof(*newslot));
newslot->curl = NULL;
newslot->in_use = 0;
+ newslot->in_multi = 0;
newslot->next = NULL;
slot = active_queue_head;
@@ -1033,6 +1040,7 @@ int start_active_slot(struct active_request_slot *slot)
slot->in_use = 0;
return 0;
}
+ slot->in_multi = 1;
/*
* We know there must be something to do, since we just added
diff --git a/http.h b/http.h
index 5ab9d9c..3339d70 100644
--- a/http.h
+++ b/http.h
@@ -60,6 +60,7 @@ struct slot_results {
struct active_request_slot {
CURL *curl;
int in_use;
+ int in_multi;
CURLcode curl_result;
long http_code;
int *finished;
--
EW
reply other threads:[~2016-09-21 21:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160921212054.17177-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).