]> sjero.net Git - wget/blobdiff - src/gnutls.c
gnutls: Fix a memory leak.
[wget] / src / gnutls.c
index 2a1d22b9ed3ad91a942d5a0261a961e776b6371d..442b1364a311b34fd171dd51302ab99c06b863b2 100644 (file)
@@ -1,5 +1,5 @@
 /* SSL support via GnuTLS library.
-   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software
    Foundation, Inc.
 
 This file is part of GNU Wget.
@@ -160,9 +160,13 @@ wgnutls_read_timeout (int fd, char *buf, int bufsize, void *arg, double timeout)
 
   do
     {
-      double next_timeout = timeout - ptimer_measure (timer);
-      if (timeout && next_timeout < 0)
-        break;
+      double next_timeout;
+      if (timeout > 0.0)
+       {
+         next_timeout = timeout - ptimer_measure (timer);
+         if (next_timeout < 0.0)
+           break;
+       }
 
       ret = GNUTLS_E_AGAIN;
       if (timeout == 0 || gnutls_record_check_pending (ctx->session)
@@ -171,15 +175,13 @@ wgnutls_read_timeout (int fd, char *buf, int bufsize, void *arg, double timeout)
           if (timeout)
             {
 #ifdef F_GETFL
-              ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK);
-              if (ret < 0)
-                return ret;
+              if (fcntl (fd, F_SETFL, flags | O_NONBLOCK))
+               break;
 #else
               /* XXX: Assume it was blocking before.  */
               const int one = 1;
-              ret = ioctl (fd, FIONBIO, &one);
-              if (ret < 0)
-                return ret;
+              if (ioctl (fd, FIONBIO, &one) < 0)
+               break;
 #endif
             }
 
@@ -187,16 +189,13 @@ wgnutls_read_timeout (int fd, char *buf, int bufsize, void *arg, double timeout)
 
           if (timeout)
             {
-              int status;
 #ifdef F_GETFL
-              status = fcntl (fd, F_SETFL, flags);
-              if (status < 0)
-                return status;
+              if (fcntl (fd, F_SETFL, flags) < 0)
+               break;
 #else
               const int zero = 0;
-              status = ioctl (fd, FIONBIO, &zero);
-              if (status < 0)
-                return status;
+              if (ioctl (fd, FIONBIO, &zero) < 0)
+               break;
 #endif
             }
         }