{"thread":{"id":"2186","subject":"[PATCH 1/3] Clean up CURL handles in unused request slots","startedAt":"2005-10-21T19:06:10Z","lastAt":"2005-10-21T19:06:10Z","messageCount":1,"participants":["Nick Hengeveld"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"10434","messageId":"20051021190610.GE6160@reactrix.com","threadId":"2186","inReplyTo":null,"subject":"[PATCH 1/3] Clean up CURL handles in unused request slots","fromName":"Nick Hengeveld","fromEmail":"nickh@reactrix.com","sentAt":"2005-10-21T19:06:10Z","receivedAt":"2005-10-21T19:06:10Z","isPatch":true,"sender":{"key":"nickh@reactrix.com","avatar":null},"body":"Clean up CURL handles in unused request slots\n\nSigned-off-by: Nick Hengeveld <nickh@reactrix.com>\n\n\n---\n\nWhile it's not clear whether this fixes any of the reported problems, it\nseems safer to close connections that we know aren't in use.\n\n http-fetch.c |   26 ++++++++++++++++++++------\n 1 files changed, 20 insertions(+), 6 deletions(-)\n\napplies-to: ce9a5a0fdd52a29e370d849a132b4509c844aca1\n24cd59bf9c4f5519e7f529cdd5bf3a9fbec72e5e\ndiff --git a/http-fetch.c b/http-fetch.c\nindex a7dc2cc..d26fae8 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -291,11 +291,7 @@ static struct active_request_slot *get_a\n \t}\n \tif (slot == NULL) {\n \t\tnewslot = xmalloc(sizeof(*newslot));\n-#ifdef NO_CURL_EASY_DUPHANDLE\n-\t\tnewslot->curl = get_curl_handle();\n-#else\n-\t\tnewslot->curl = curl_easy_duphandle(curl_default);\n-#endif\n+\t\tnewslot->curl = NULL;\n \t\tnewslot->in_use = 0;\n \t\tnewslot->next = NULL;\n \n@@ -311,6 +307,14 @@ static struct active_request_slot *get_a\n \t\tslot = newslot;\n \t}\n \n+\tif (slot->curl == NULL) {\n+#ifdef NO_CURL_EASY_DUPHANDLE\n+\t\tslot->curl = get_curl_handle();\n+#else\n+\t\tslot->curl = curl_easy_duphandle(curl_default);\n+#endif\n+\t}\n+\n \tactive_requests++;\n \tslot->in_use = 1;\n \tslot->done = 0;\n@@ -612,6 +616,7 @@ void process_curl_messages(void)\n void process_request_queue(void)\n {\n \tstruct transfer_request *request = request_queue_head;\n+\tstruct active_request_slot *slot = active_queue_head;\n \tint num_transfers;\n \n \twhile (active_requests < max_requests && request != NULL) {\n@@ -624,6 +629,14 @@ void process_request_queue(void)\n \t\t}\n \t\trequest = request->next;\n \t}\n+\n+\twhile (slot != NULL) {\n+\t\tif (!slot->in_use && slot->curl != NULL) {\n+\t\t\tcurl_easy_cleanup(slot->curl);\n+\t\t\tslot->curl = NULL;\n+\t\t}\n+\t\tslot = slot->next;\n+\t}\t\t\t\t\n }\n #endif\n \n@@ -1297,7 +1310,8 @@ int main(int argc, char **argv)\n #endif\n \tslot = active_queue_head;\n \twhile (slot != NULL) {\n-\t\tcurl_easy_cleanup(slot->curl);\n+\t\tif (slot->curl != NULL)\n+\t\t\tcurl_easy_cleanup(slot->curl);\n \t\tslot = slot->next;\n \t}\n #ifdef USE_CURL_MULTI\n---\n0.99.8.GIT\n"}]}