summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-04-20 06:51:07 +0000
committerJim Meyering <jim@meyering.net>2004-04-20 06:51:07 +0000
commit335e3339ff4e39031deae9536736381cfb441dd9 (patch)
treec93ef0c3741aaa0650091a660dff0ff498edbc55 /lib
parent4ef7ed5d4996c812f4ac4b60f1d0905b48aad2c7 (diff)
downloadcoreutils-335e3339ff4e39031deae9536736381cfb441dd9.tar.xz
(getndelim2): Upon realloc failure, don't leak memory.
Diffstat (limited to 'lib')
-rw-r--r--lib/getndelim2.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/getndelim2.c b/lib/getndelim2.c
index 395946259..2b6dc1157 100644
--- a/lib/getndelim2.c
+++ b/lib/getndelim2.c
@@ -1,7 +1,7 @@
/* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters,
with bounded memory allocation.
- Copyright (C) 1993, 1996, 1997, 1998, 2000, 2003 Free Software
+ Copyright (C) 1993, 1996, 1997, 1998, 2000, 2003, 2004 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -80,15 +80,17 @@ getndelim2 (char **lineptr, size_t *linesize, size_t nmax,
{
size_t newlinesize =
(*linesize > MIN_CHUNK ? 2 * *linesize : *linesize + MIN_CHUNK);
+ char *p;
if (! (*linesize < newlinesize && newlinesize <= nmax))
newlinesize = nmax;
*linesize = newlinesize;
nbytes_avail = *linesize + *lineptr - read_pos;
- *lineptr = realloc (*lineptr, *linesize);
- if (!*lineptr)
+ p = realloc (*lineptr, *linesize);
+ if (!p)
return -1;
+ *lineptr = p;
read_pos = *linesize - nbytes_avail + *lineptr;
}