This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
error.c (error_tail): Don't leak upon realloc failure.
- From: Jim Meyering <jim at meyering dot net>
- To: libc-alpha at gnu dot org
- Date: Tue, 20 Apr 2004 14:50:40 +0200
- Subject: error.c (error_tail): Don't leak upon realloc failure.
Here's a proposed patch to avoid a leak:
One possible variation, for portability to some older systems:
rather than just `free (wmessage);', add
if (wmessage)
free (wmessage);
2004-04-20 Jim Meyering <jim@meyering.net>
* misc/error.c (error_tail): Don't leak upon realloc failure.
Index: misc/error.c
===================================================================
RCS file: /cvs/glibc/libc/misc/error.c,v
retrieving revision 1.33
diff -u -p -r1.33 error.c
--- misc/error.c 30 Aug 2003 08:30:40 -0000 1.33
+++ misc/error.c 20 Apr 2004 12:01:49 -0000
@@ -189,21 +189,23 @@ error_tail (int status, int errnum, cons
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
else
{
+ char *p;
if (wmessage != NULL && len / 2 < ALLOCA_LIMIT)
wmessage = NULL;
- wmessage = (wchar_t *) realloc (wmessage,
- len * sizeof (wchar_t));
+ p = (wchar_t *) realloc (wmessage, len * sizeof (wchar_t));
- if (wmessage == NULL)
+ if (p == NULL)
{
+ free (wmessage);
fputws_unlocked (L"out of memory\n", stderr);
return;
}
+ wmessage = p;
}
memset (&st, '\0', sizeof (st));
- tmp =message;
+ tmp = message;
}
while ((res = mbsrtowcs (wmessage, &tmp, len, &st)) == len);