]> 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 6c0a4464a71f49effc6dae464e353a85a8a17dc5..98a422da8d7cda181dc01721aeffd3e126a90854 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.238 2015/09/12 18:10:42 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.239 2015/09/16 18:21:26 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;