[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
error.c: don't leak upon realloc failure
From: |
Jim Meyering |
Subject: |
error.c: don't leak upon realloc failure |
Date: |
Tue, 20 Apr 2004 09:43:32 +0200 |
Here's a proposed patch to avoid a leak in the unusual event
that realloc is used, and fails.
2004-04-20 Jim Meyering <address@hidden>
* error.c (error_tail): Don't leak upon realloc failure.
Index: gettext-tools/lib/error.c
===================================================================
RCS file: /cvs/gettext/gettext/gettext-tools/lib/error.c,v
retrieving revision 1.5
diff -u -p -r1.5 error.c
--- gettext-tools/lib/error.c 24 Aug 2003 19:50:42 -0000 1.5
+++ gettext-tools/lib/error.c 20 Apr 2004 07:36:41 -0000
@@ -1,5 +1,5 @@
/* Error handler for noninteractive utilities
- Copyright (C) 1990-1998, 2000-2003 Free Software Foundation, Inc.
+ Copyright (C) 1990-1998, 2000-2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
@@ -197,21 +197,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);
- error.c: don't leak upon realloc failure,
Jim Meyering <=