]> granicus.if.org Git - file/commitdiff
don't leak if realloc fails.
authorChristos Zoulas <christos@zoulas.com>
Tue, 11 Apr 2000 02:06:57 +0000 (02:06 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 11 Apr 2000 02:06:57 +0000 (02:06 +0000)
src/apprentice.c

index 07429c8ca134f4316b8448fdc017e109e9102a64..2c5875ae0d25d5887dd18bd182cdbbe6ce5fff7b 100644 (file)
@@ -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];