From: Christos Zoulas Date: Wed, 12 Nov 2014 15:28:34 +0000 (+0000) Subject: Simplify freeing of the map and remove bogus frees in the user buffer case. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=113a1cbdafc8d4011e7f77e603e5e3c047f8cce8;p=file Simplify freeing of the map and remove bogus frees in the user buffer case. --- diff --git a/src/apprentice.c b/src/apprentice.c index 6085bfb2..d4fb8afb 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.222 2014/11/11 17:46:05 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.223 2014/11/12 15:28:34 christos Exp $") #endif /* lint */ #include "magic.h" @@ -535,17 +535,21 @@ apprentice_unmap(struct magic_map *map) { if (map == NULL) return; - if (map->p != NULL && map->type != MAP_TYPE_USER) { + + switch (map->type) { #ifdef QUICK - if (map->type == MAP_TYPE_MMAP) + case MAP_TYPE_MMAP: + if (map->p) (void)munmap(map->p, map->len); - else + break; #endif + case MAP_TYPE_MALLOC: free(map->p); - } else { - uint32_t j; - for (j = 0; j < MAGIC_SETS; j++) - free(map->magic[j]); + break; + case MAP_TYPE_USER: + break; + default: + abort(); } free(map); }