Hi Simon,
I noticed that our getdelim replacement can leak when the initial realloc
fails. While that can happen only when *N is 0 and *LINEPTR is malloc'd,
I think it's worth fixing, if only to avoid further discussion on the topic.
Here's the fix.
Ok to apply?
* lib/getdelim.c (getdelim): Don't leak memory upon failed realloc.
diff --git a/lib/getdelim.c b/lib/getdelim.c
index 0547c7f..7c6f326 100644
--- a/lib/getdelim.c
+++ b/lib/getdelim.c
@@ -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 (;;)
--
1.5.4.3.341.g956c8c