]> sjero.net Git - wget/commitdiff
Fix memory leak.
authorGijs van Tulder <gvtulder@gmail.com>
Sat, 28 Jan 2012 13:08:52 +0000 (14:08 +0100)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Sat, 28 Jan 2012 13:08:52 +0000 (14:08 +0100)
src/ChangeLog
src/http.c
src/retr.c

index 141a47d42f821e2bd9c16109863ec4c8d7217894..e10d4c0233ba8c564de84f926288a6a34bf7bf90 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-27  Gijs van Tulder  <gvtulder@gmail.com>
+
+       * retr.c (fd_read_body): Fix a memory leak with chunked responses.
+       * http.c (skip_short_body): Fix the same memory leak.
+
 2012-01-09  Gijs van Tulder  <gvtulder@gmail.com>
 
        * init.c: Disable WARC compression if zlib is disabled.
index 69789fcd4770da72ecdaf962e7f38b4c893b8c1b..78725796e66516a0e27902a14afab6965ea3a0f1 100644 (file)
@@ -951,9 +951,12 @@ skip_short_body (int fd, wgint contlen, bool chunked)
                 break;
 
               remaining_chunk_size = strtol (line, &endl, 16);
+              xfree (line);
+
               if (remaining_chunk_size == 0)
                 {
-                  fd_read_line (fd);
+                  line = fd_read_line (fd);
+                  xfree_null (line);
                   break;
                 }
             }
@@ -978,8 +981,13 @@ skip_short_body (int fd, wgint contlen, bool chunked)
         {
           remaining_chunk_size -= ret;
           if (remaining_chunk_size == 0)
-            if (fd_read_line (fd) == NULL)
-              return false;
+            {
+              char *line = fd_read_line (fd);
+              if (line == NULL)
+                return false;
+              else
+                xfree (line);
+            }
         }
 
       /* Safe even if %.*s bogusly expects terminating \0 because
index 3df582b8f500d3278d0230d69746e216f51cabef..f57b2c6d68fb385f6c999e11929802148edf6b29 100644 (file)
@@ -307,11 +307,16 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
                 }
 
               remaining_chunk_size = strtol (line, &endl, 16);
+              xfree (line);
+
               if (remaining_chunk_size == 0)
                 {
                   ret = 0;
-                  if (fd_read_line (fd) == NULL)
+                  line = fd_read_line (fd);
+                  if (line == NULL)
                     ret = -1;
+                  else
+                    xfree (line);
                   break;
                 }
             }
@@ -371,11 +376,16 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
             {
               remaining_chunk_size -= ret;
               if (remaining_chunk_size == 0)
-                if (fd_read_line (fd) == NULL)
-                  {
-                    ret = -1;
-                    break;
-                  }
+                {
+                  char *line = fd_read_line (fd);
+                  if (line == NULL)
+                    {
+                      ret = -1;
+                      break;
+                    }
+                  else
+                    xfree (line);
+                }
             }
         }