--- hostip.c.orig	Thu Apr  1 00:21:06 2004
+++ hostip.c	Thu Apr  1 00:14:06 2004
@@ -627,7 +627,7 @@
     timeout = conn->data->set.timeout;
 
   /* Wait for the name resolve query to complete. */
-  while (timeout > 0) {
+  while (1) {
     int nfds=0;
     fd_set read_fds, write_fds;
     struct timeval *tvp, tv, store;
@@ -651,6 +651,12 @@
     ares_process(data->state.areschannel, &read_fds, &write_fds);
 
     timeout -= Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */
+    if (timeout <= 0) {
+      /* our timeout, so we must force ares timeout (and free the query) */
+      ares_force_timeouts(data->state.areschannel);
+      break;
+    }
+      
   }
 
   /* Operation complete, if the lookup was successful we now have the entry
@@ -661,7 +667,7 @@
 
   if(!conn->async.dns) {
     /* a name was not resolved */
-    if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) {
+    if((timeout <= 0) || (conn->async.status == ARES_ETIMEOUT)) {
       failf(data, "Resolving host timed out: %s", conn->name);
       rc = CURLE_OPERATION_TIMEDOUT;
     }

