On 20/11/2001 10:12:05 Daniel Stenberg wrote:

>This subject says it all. The leak is minor, the fix could be made
>something like this:
>
>diff -u -r1.21 utils.c
>--- utils.c     2001/05/27 19:35:12     1.21
>+++ utils.c     2001/11/20 10:10:17
>@@ -903,7 +903,12 @@
>   while (fgets (line + length, bufsize - length, fp))
>     {
>       length += strlen (line + length);
>-      assert (length > 0);
>+      if (0 == length)
>+        {
>+          /* bad input file */
>+          xfree(line);
>+          return NULL;
>+        }
>       if (line[length - 1] == '\n')
>        break;
>       /* fgets() guarantees to read the whole line, or to use up the
>

It's not just a memory leak. Length <= 0 is declared as a "can't happen".
If length is zero, wget will suddenly end due to the assert.
If a bad input file can lead to length being zero, then using assert is bad
on principle. One should never assert external input.


--
Csaba R�duly, Software Engineer                           Sophos Anti-Virus
email: [EMAIL PROTECTED]                        http://www.sophos.com
US Support: +1 888 SOPHOS 9                     UK Support: +44 1235 559933

Reply via email to