Fix issue related with the use of ares_timeout() result.
diff --git a/CHANGES b/CHANGES
index 803bf0f..ebda300 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,8 @@
                                   Changelog
 
 Daniel S (3 October 2007)
+- Yang Tse, fix issue related with the use of ares_timeout() result.
+
 - Alexey Pesternikov introduced CURLOPT_OPENSOCKETFUNCTION and
   CURLOPT_OPENSOCKETDATA to set a callback that allows an application to
   replace the socket() call used by libcurl. It basically allows the app to
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index cfba051..be84ebd 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -33,6 +33,7 @@
  o re-used handle transfers with SFTP
  o curl_easy_escape() problem with byte values >= 128
  o handles chunked-encoded CONNECT responses
+ o misuse of ares_timeout() result
 
 This release includes the following known bugs:
 
diff --git a/lib/hostares.c b/lib/hostares.c
index 4c49411..81707ac 100644
--- a/lib/hostares.c
+++ b/lib/hostares.c
@@ -109,7 +109,8 @@
 
 {
   struct timeval maxtime;
-  struct timeval timeout;
+  struct timeval timebuf;
+  struct timeval *timeout;
   int max = ares_getsock(conn->data->state.areschannel,
                          (int *)socks, numsocks);
 
@@ -117,10 +118,10 @@
   maxtime.tv_sec = CURL_TIMEOUT_RESOLVE;
   maxtime.tv_usec = 0;
 
-  ares_timeout(conn->data->state.areschannel, &maxtime, &timeout);
+  timeout = ares_timeout(conn->data->state.areschannel, &maxtime, &timebuf);
 
   Curl_expire(conn->data,
-              (timeout.tv_sec * 1000) + (timeout.tv_usec/1000) );
+              (timeout->tv_sec * 1000) + (timeout->tv_usec/1000));
 
   return max;
 }
@@ -254,7 +255,7 @@
     tvp = ares_timeout(data->state.areschannel, &store, &tv);
 
     /* use the timeout period ares returned to us above */
-    ares_waitperform(conn, tv.tv_sec * 1000 + tv.tv_usec/1000);
+    ares_waitperform(conn, tvp->tv_sec * 1000 + tvp->tv_usec/1000);
 
     if(conn->async.done)
       break;