Mail Archives: djgpp-workers/2002/01/14/18:08:36
Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk> wrote:
>Index: src/libc/posix/regex/regcomp.c
>===================================================================
>RCS file: /cvs/djgpp/djgpp/src/libc/posix/regex/regcomp.c,v
>retrieving revision 1.5
>diff -p -u -3 -r1.5 regcomp.c
>--- src/libc/posix/regex/regcomp.c 2001/06/09 20:50:55 1.5
>+++ src/libc/posix/regex/regcomp.c 2002/01/05 12:27:40
>@@ -1,3 +1,4 @@
>+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
> /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
> /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
> #include <sys/types.h>
>@@ -1014,14 +1015,24 @@ register struct parse *p;
> nbytes = nc / CHAR_BIT * css;
> if (p->g->sets == NULL)
> p->g->sets = (cset *)malloc(nc * sizeof(cset));
>- else
>- p->g->sets = (cset *)realloc((char *)p->g->sets,
>+ else {
>+ cset *temp = (cset *)realloc((char *)p->g->sets,
> nc *
>sizeof(cset));
>+ /* Don't leak memory if realloc() fails. */
>+ if (temp == NULL)
>+ free(p->g->sets);
>+ p->g->sets = temp;
>+ }
> if (p->g->setbits == NULL)
> p->g->setbits = (uch *)malloc(nbytes);
> else {
>- p->g->setbits = (uch *)realloc((char
>*)p->g->setbits,
>- nbytes);
>+ uch *temp = (uch *)realloc((char *)p->g->setbits,
>+ nbytes);
>+ /* Don't leak memory if realloc() fails. */
>+ if (temp == NULL)
>+ free(p->g->setbits);
>+ p->g->setbits = temp;
>+
> /* xxx this isn't right if setbits is now NULL */
> for (i = 0; i < no; i++)
> p->g->sets[i].ptr = p->g->setbits +
>css*(i/CHAR_BIT);
Unfortunately that's not enough. There's deeper problems with memory allocation. More proper fixes are included in my NLS patchset. I can't extract them right now by myself because I'm currently in the business trip until the middle of February.
--
alexander aganichev
url: http://aaganichev.narod.ru
- Raw text -