]> granicus.if.org Git - file/commitdiff
this will happen on systems that don't have mmap(2). Typically
authorChristos Zoulas <christos@zoulas.com>
Wed, 16 Sep 2015 18:34:21 +0000 (18:34 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 16 Sep 2015 18:34:21 +0000 (18:34 +0000)
MALLOC type entries happen during regular parsing or compilation
and are allocated in coalesce_entries(). But they will also occur
when QUICK is not defined (i.e. when the target system does not
have mmap(2)).

src/apprentice.c

index 95174d03889e5021b5d7ee8fc68baca04c901a22..2089e63a97aab23333c51f0a85f15eebf2e69905 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.239 2015/09/16 18:21:26 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.240 2015/09/16 18:34:21 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -553,9 +553,13 @@ apprentice_unmap(struct magic_map *map)
                break;
 #endif
        case MAP_TYPE_MALLOC:
-               free(map->p);
-               for (i = 0; i < MAGIC_SETS; i++)
+               for (i = 0; i < MAGIC_SETS; i++) {
+                       if ((char *)map->magic[i] >= (char *)map->p &&
+                           (char *)map->magic[i] < (char *)map->p + map->len)
+                               continue;
                        free(map->magic[i]);
+               }
+               free(map->p);
                break;
        case MAP_TYPE_USER:
                break;