aboutsummaryrefslogtreecommitdiff
path: root/libio/iogetdelim.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-12-29 15:57:15 +0000
committerUlrich Drepper <drepper@redhat.com>2001-12-29 15:57:15 +0000
commitd1dddedf7893fe70ed5d429485c8bcd0ab43f285 (patch)
tree99420c13234130854769150b8d81f5fe1d2528e3 /libio/iogetdelim.c
parent9403ec5d23e7dc209361b3dbae2fdc184e1684aa (diff)
downloadglibc-d1dddedf7893fe70ed5d429485c8bcd0ab43f285.zip
glibc-d1dddedf7893fe70ed5d429485c8bcd0ab43f285.tar.gz
glibc-d1dddedf7893fe70ed5d429485c8bcd0ab43f285.tar.bz2
Realloc error handling memory leak fix.
Diffstat (limited to 'libio/iogetdelim.c')
-rw-r--r--libio/iogetdelim.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c
index e648bf0..edc5228 100644
--- a/libio/iogetdelim.c
+++ b/libio/iogetdelim.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -96,15 +96,18 @@ _IO_getdelim (lineptr, n, delimiter, fp)
needed = cur_len + len + 1;
if (needed > *n)
{
+ char *new_lineptr;
+
if (needed < 2 * *n)
needed = 2 * *n; /* Be generous. */
- *n = needed;
- *lineptr = (char *) realloc (*lineptr, needed);
- if (*lineptr == NULL)
+ new_lineptr = (char *) realloc (*lineptr, needed);
+ if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
+ *lineptr = new_lineptr;
+ *n = needed;
}
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;