lib/getdelim.c (getdelim): Don't leak memory upon failed realloc.
authorJim Meyering <meyering@redhat.com>
Sat, 1 Mar 2008 11:14:27 +0000 (12:14 +0100)
committerJim Meyering <meyering@redhat.com>
Sun, 2 Mar 2008 16:24:56 +0000 (17:24 +0100)
ChangeLog
lib/getdelim.c

index 69e78c84f9be63ac5668aaa9a66f313e0007aef3..29dc04a8b388cf532545e88c0f8e5abf43df12a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2008-03-02  Jim Meyering  <meyering@redhat.com>
 
+       * lib/getdelim.c (getdelim): Don't leak memory upon failed realloc.
+
        Remove useless "if" tests before free.  Deprecate "free" module.
        * doc/posix-functions/free.texi: Mention that this
        module is no longer useful.
index 0547c7fae2c8cd25b0b4005fb58f10c6c9d1ae1a..7c6f3265a052b3e6f2c085df6d6bf21461eada75 100644 (file)
@@ -69,13 +69,15 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
 
   if (*lineptr == NULL || *n == 0)
     {
+      char *new_lineptr;
       *n = 120;
-      *lineptr = (char *) realloc (*lineptr, *n);
-      if (*lineptr == NULL)
+      new_lineptr = (char *) realloc (*lineptr, *n);
+      if (new_lineptr == NULL)
        {
          result = -1;
          goto unlock_return;
        }
+      *lineptr = new_lineptr;
     }
 
   for (;;)