Mercurial > hg > octave-lyh > gnulib-hg
changeset 9750:98643d71bad2
lib/getdelim.c (getdelim): Don't leak memory upon failed realloc.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sat, 01 Mar 2008 12:14:27 +0100 |
parents | daf5ba9fe2d9 |
children | d185045bb021 |
files | ChangeLog lib/getdelim.c |
diffstat | 2 files changed, 6 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/lib/getdelim.c +++ b/lib/getdelim.c @@ -69,13 +69,15 @@ 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 (;;)