Date: Mon, 14 Jan 2002 17:36:40 -0500 From: AAganichev AT netscape DOT net (Alexander Aganichev) To: djgpp-workers AT delorie DOT com Subject: RE: Re: Memory leaks fixes Message-ID: <4A81FF7A.4320CCDC.09ACFA57@netscape.net> X-Mailer: Atlas Mailer 1.0 Content-Type: text/plain; charset=iso-8859-1 Reply-To: djgpp-workers AT delorie DOT com Richard Dawe 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 >@@ -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