PR/341: Jan Kaluza: Fix memory leak
authorChristos Zoulas <christos@zoulas.com>
Tue, 1 Apr 2014 15:57:28 +0000 (15:57 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 1 Apr 2014 15:57:28 +0000 (15:57 +0000)
src/apprentice.c

index 797e43a3e061b12513fa2dd9fc4c111a79f6392c..aaff84e580a73c88725f1ae91d3db983edd20f64 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.201 2014/03/14 17:38:33 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.202 2014/03/14 18:48:11 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -517,14 +517,18 @@ apprentice_unmap(struct magic_map *map)
 {
        if (map == NULL)
                return;
-       if (map->p == NULL)
-               return;
+       if (map->p != NULL) {
 #ifdef QUICK
-       if (map->len)
-               (void)munmap(map->p, map->len);
-       else
+               if (map->len)
+                       (void)munmap(map->p, map->len);
+               else
 #endif
                free(map->p);
+       } else {
+               uint32_t j;
+               for (j = 0; j < MAGIC_SETS; j++)
+                       free(map->magic[j]);
+       }
        free(map);
 }
 
@@ -1290,11 +1294,7 @@ out:
                magic_entry_free(mset[j].me, mset[j].count);
 
        if (errs) {
-               for (j = 0; j < MAGIC_SETS; j++) {
-                       if (map->magic[j])
-                               free(map->magic[j]);
-               }
-               free(map);
+               apprentice_unmap(map);
                return NULL;
        }
        return map;