lib/getdelim.c (getdelim): Don't leak memory upon failed realloc.
[gnulib.git] / lib / getdelim.c
index 0547c7f..7c6f326 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 (;;)