From: Christos Zoulas Date: Tue, 11 Apr 2000 02:06:57 +0000 (+0000) Subject: don't leak if realloc fails. X-Git-Tag: FILE3_30~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0453fbcf9963a8714f3268425fa42a25eba41a9;p=file don't leak if realloc fails. --- diff --git a/src/apprentice.c b/src/apprentice.c index 07429c8c..2c5875ae 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -33,7 +33,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$Id: apprentice.c,v 1.30 1999/11/28 20:02:28 christos Exp $") +FILE_RCSID("@(#)$Id: apprentice.c,v 1.31 2000/04/11 02:06:57 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -185,15 +185,17 @@ int *ndx, check; #define ALLOC_INCR 200 if (nd+1 >= maxmagic){ maxmagic += ALLOC_INCR; - if ((magic = (struct magic *) realloc(magic, - sizeof(struct magic) * - maxmagic)) == NULL) { + if ((m = (struct magic *) realloc(magic, sizeof(struct magic) * + maxmagic)) == NULL) { (void) fprintf(stderr, "%s: Out of memory.\n", progname); + if (magic) + free(magic); if (check) return -1; else exit(1); } + magic = m; memset(&magic[*ndx], 0, sizeof(struct magic) * ALLOC_INCR); } m = &magic[*ndx];