Index: hostares.c =================================================================== RCS file: /cvsroot/curl/curl/lib/hostares.c,v retrieving revision 1.9 diff -u -r1.9 hostares.c --- hostares.c 6 Oct 2004 07:50:18 -0000 1.9 +++ hostares.c 7 Feb 2005 19:51:42 -0000 @@ -246,10 +246,7 @@ } else rc = CURLE_OPERATION_TIMEDOUT; - - /* close the connection, since we can't return failure here without - cleaning up this connection properly */ - Curl_disconnect(conn); + conn->bits.close = TRUE; } return rc; @@ -291,7 +288,7 @@ /* areschannel is already setup in the Curl_open() function */ ares_gethostbyname(data->state.areschannel, hostname, PF_INET, - Curl_addrinfo4_callback, conn); + (ares_callback)Curl_addrinfo4_callback, conn); *waitp = TRUE; /* please wait for the response */ } Index: hostasyn.c =================================================================== RCS file: /cvsroot/curl/curl/lib/hostasyn.c,v retrieving revision 1.7 diff -u -r1.7 hostasyn.c --- hostasyn.c 6 Oct 2004 07:50:18 -0000 1.7 +++ hostasyn.c 7 Feb 2005 19:51:42 -0000 @@ -108,12 +108,13 @@ * * The storage operation locks and unlocks the DNS cache. */ -static void addrinfo_callback(void *arg, /* "struct connectdata *" */ - int status, - void *addr) +static CURLcode addrinfo_callback(void *arg, /* "struct connectdata *" */ + int status, + void *addr) { struct connectdata *conn = (struct connectdata *)arg; struct Curl_dns_entry *dns = NULL; + CURLcode rc = CURLE_OK; conn->async.status = status; @@ -135,13 +136,17 @@ dns = Curl_cache_addr(data, ai, conn->async.hostname, conn->async.port); - if(!dns) + if(!dns) { /* failed to store, cleanup and return error */ Curl_freeaddrinfo(ai); + rc = CURLE_OUT_OF_MEMORY; + } if(data->share) Curl_share_unlock(data, CURL_LOCK_DATA_DNS); } + else + rc = CURLE_OUT_OF_MEMORY; } conn->async.dns = dns; @@ -153,21 +158,22 @@ /* ipv4: The input hostent struct will be freed by ares when we return from this function */ + return rc; } -void Curl_addrinfo4_callback(void *arg, /* "struct connectdata *" */ - int status, - struct hostent *hostent) +CURLcode Curl_addrinfo4_callback(void *arg, /* "struct connectdata *" */ + int status, + struct hostent *hostent) { - addrinfo_callback(arg, status, hostent); + return addrinfo_callback(arg, status, hostent); } #ifdef CURLRES_IPV6 -void Curl_addrinfo6_callback(void *arg, /* "struct connectdata *" */ - int status, - struct addrinfo *ai) +CURLcode Curl_addrinfo6_callback(void *arg, /* "struct connectdata *" */ + int status, + struct addrinfo *ai) { - addrinfo_callback(arg, status, ai); + return addrinfo_callback(arg, status, ai); } #endif Index: hostthre.c =================================================================== RCS file: /cvsroot/curl/curl/lib/hostthre.c,v retrieving revision 1.17 diff -u -r1.17 hostthre.c --- hostthre.c 19 Jan 2005 10:20:55 -0000 1.17 +++ hostthre.c 7 Feb 2005 19:51:44 -0000 @@ -190,7 +190,7 @@ curr_proc, &mutex_waiting, 0, FALSE, DUPLICATE_SAME_ACCESS)) { /* failed to duplicate the mutex, no point in continuing */ - return 0; + return -1; } /* Sharing the same _iob[] element with our parent thread should @@ -214,12 +214,10 @@ SetEvent(td->event_resolved); if (he) { - Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he); - rc = 1; + rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he); } else { - Curl_addrinfo4_callback(conn, (int)WSAGetLastError(), NULL); - rc = 0; + rc = Curl_addrinfo4_callback(conn, (int)WSAGetLastError(), NULL); } TRACE(("Winsock-error %d, addr %s\n", conn->async.status, he ? inet_ntoa(*(struct in_addr*)he->h_addr) : "unknown")); @@ -260,7 +258,7 @@ curr_proc, &mutex_waiting, 0, FALSE, DUPLICATE_SAME_ACCESS)) { /* failed to duplicate the mutex, no point in continuing */ - return 0; + return -1; } #ifndef _WIN32_WCE @@ -286,10 +284,10 @@ #ifdef DEBUG_THREADING_GETADDRINFO dump_addrinfo (conn, res); #endif - Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res); + rc = Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res); } else { - Curl_addrinfo6_callback(conn, (int)WSAGetLastError(), NULL); + rc = Curl_addrinfo6_callback(conn, (int)WSAGetLastError(), NULL); TRACE(("Winsock-error %d, no address\n", conn->async.status)); } } @@ -493,7 +491,11 @@ if (!conn->async.dns) { /* a name was not resolved */ - if (td->thread_status == (DWORD)-1 || conn->async.status == NO_DATA) { + if (td->thread_status == CURLE_OUT_OF_MEMORY) { + rc = CURLE_OUT_OF_MEMORY; + failf(data, "Could not resolve host: %s", curl_easy_strerror(rc)); + } + else if (td->thread_status == (DWORD)-1 || conn->async.status == NO_DATA) { failf(data, "Resolving host timed out: %s", conn->host.name); rc = CURLE_OPERATION_TIMEDOUT; } @@ -508,10 +510,8 @@ destroy_thread_data(&conn->async); - if(CURLE_OK != rc) - /* close the connection, since we must not return failure from here - without cleaning up this connection properly */ - Curl_disconnect(conn); + if(!conn->async.dns) + conn->bits.close = TRUE; return (rc); } Index: transfer.c =================================================================== RCS file: /cvsroot/curl/curl/lib/transfer.c,v retrieving revision 1.266 diff -u -r1.266 transfer.c --- transfer.c 4 Feb 2005 13:42:41 -0000 1.266 +++ transfer.c 7 Feb 2005 19:51:47 -0000 @@ -2038,7 +2038,8 @@ if(CURLE_OK == res) /* Resolved, continue with the connection */ res = Curl_async_resolved(*conn); - } + else + (void)Curl_disconnect(*conn); } if(res) break; Index: hostip.h =================================================================== RCS file: /cvsroot/curl/curl/lib/hostip.h,v retrieving revision 1.39 diff -u -r1.39 hostip.h --- hostip.h 25 Jan 2005 00:06:29 -0000 1.39 +++ hostip.h 7 Feb 2005 19:53:50 -0000 @@ -199,14 +199,14 @@ /* This is the callback function that is used when we build with asynch resolve, ipv4 */ -void Curl_addrinfo4_callback(void *arg, - int status, - struct hostent *hostent); +CURLcode Curl_addrinfo4_callback(void *arg, + int status, + struct hostent *hostent); /* This is the callback function that is used when we build with asynch resolve, ipv6 */ -void Curl_addrinfo6_callback(void *arg, - int status, - struct addrinfo *ai); +CURLcode Curl_addrinfo6_callback(void *arg, + int status, + struct addrinfo *ai); /* [ipv4 only] Creates a Curl_addrinfo struct from a numerical-only IP