--- lib/multi.c.orig Sat Jan 27 21:22:02 2007 +++ lib/multi.c Wed Feb 28 17:40:26 2007 @@ -1986,3 +1986,51 @@ } } #endif + +/* + * Walks through all easy handles and returns the number of + * easy connections in the multi stack that are using the + * given 'connection'. + */ +int Curl_multi_connection_used(struct Curl_multi *multi, + struct connectdata *connection) +{ + int count = 0; + struct Curl_one_easy *easy; + + easy = multi->easy.next; + while (easy) { + if (easy->easy_conn == connection) { + fprintf(stderr, "Used in easy = 0x%x\n", easy); + count++; + } + easy=easy->next; + } + + fprintf(stderr, "Connection 0x%x, multi 0x%x: %d references.\n", + connection, multi, count); + + return count; +} + +/* + * Walks through all easy handles and sets the easy_conn fields + * that are equal to 'connection' to NULL. Also sets easy's state + * to CURLM_STATE_COMPLETED. + */ +void Curl_multi_dissociate_connection(struct Curl_multi *multi, + struct connectdata *connection) +{ + struct Curl_one_easy *easy; + + easy = multi->easy.next; + while (easy) { + if (easy->easy_conn == connection) { + easy->easy_conn = NULL; + easy->state = CURLM_STATE_COMPLETED; + } + easy=easy->next; + } + + return; +} --- lib/url.c.orig Sun Jan 28 22:45:22 2007 +++ lib/url.c Wed Feb 28 17:53:14 2007 @@ -553,6 +553,10 @@ data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */ data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */ +#if defined(__FreeBSD_version) + data->set.no_signal = TRUE; /* different handling of signals and threads */ +#endif /* __FreeBSD_version */ + /* This no longer creates a connection cache here. It is instead made on the first call to curl_easy_perform() or when the handle is added to a multi stack. */ @@ -1835,6 +1839,18 @@ signalPipeClose(conn->recv_pipe); } + /* This connection can be used by some other easy thingy. If + * not, then we should clean the easy's easy_conn field to + * avoid storing the freed pointer. */ + if (data->magic == CURLEASY_MAGIC_NUMBER) { + if (Curl_multi_connection_used(data->multi, conn) > 1000) { + return CURLE_OK; + } else { + Curl_multi_dissociate_connection(data->multi, conn); + } + } + + fprintf(stderr, "Freeing connection 0x%x\n", conn); conn_free(conn); return CURLE_OK; --- lib/multiif.h.orig Mon Oct 23 06:47:06 2006 +++ lib/multiif.h Wed Feb 28 16:53:47 2007 @@ -32,6 +32,12 @@ bool Curl_multi_canPipeline(struct Curl_multi* multi); +int Curl_multi_connection_used(struct Curl_multi *multi, + struct connectdata *connection); + +void Curl_multi_dissociate_connection(struct Curl_multi *multi, + struct connectdata *connection); + /* the write bits start at bit 16 for the *getsock() bitmap */ #define GETSOCK_WRITEBITSTART 16