]> granicus.if.org Git - file/commitdiff
Simplify freeing of the map and remove bogus frees in the user buffer case.
authorChristos Zoulas <christos@zoulas.com>
Wed, 12 Nov 2014 15:28:34 +0000 (15:28 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 12 Nov 2014 15:28:34 +0000 (15:28 +0000)
src/apprentice.c

index 6085bfb2816edf54df4653839dca0d3c3b5802ca..d4fb8afb3f6ba1a70fb8bd84ddb9edc464e45e7f 100644 (file)
@@ -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);
 }