*** curl-7.20.0-orig/lib/hostip.c	2010-01-24 14:42:54.000000000 -0800
--- curl-7.20.0/lib/hostip.c	2010-03-22 12:18:03.000000000 -0700
***************
*** 571,585 ****
      return CURLRESOLV_TIMEDOUT;
  
    if (timeout > 0) {
-     /* This allows us to time-out from the name resolver, as the timeout
-        will generate a signal and we will siglongjmp() from that here.
-        This technique has problems (see alarmfunc). */
-       if(sigsetjmp(curl_jmpenv, 1)) {
-         /* this is coming from a siglongjmp() after an alarm signal */
-         failf(data, "name lookup timed out");
-         return CURLRESOLV_ERROR;
-       }
- 
      /*************************************************************
       * Set signal handler to catch SIGALRM
       * Store the old value to be able to set it back later!
--- 571,576 ----
***************
*** 607,612 ****
--- 598,616 ----
      prev_alarm = alarm((unsigned int) (timeout/1000L));
    }
  
+   /* This allows us to time-out from the name resolver, as the timeout
+      will generate a signal and we will siglongjmp() from that here.
+      This technique has problems (see alarmfunc).
+      This should be the last thing we do before calling Curl_resolv(),
+      as otherwise we'd have to worry about variables that get modified
+      before we invoke Curl_resolv() (and thus use "volatile"). */
+   if(sigsetjmp(curl_jmpenv, 1)) {
+     /* this is coming from a siglongjmp() after an alarm signal */
+     failf(data, "name lookup timed out");
+     rc = CURLRESOLV_ERROR;
+     goto clean_up;
+   }
+ 
  #else
  #ifndef CURLRES_ASYNCH
    if(timeoutms)
***************
*** 621,626 ****
--- 625,632 ----
     */
    rc = Curl_resolv(conn, hostname, port, entry);
  
+ clean_up:
+ 
  #ifdef USE_ALARM_TIMEOUT
    if (timeout > 0) {
  

