]> granicus.if.org Git - file/commitdiff
fix memory leak.
authorChristos Zoulas <christos@zoulas.com>
Tue, 11 Nov 2014 17:46:05 +0000 (17:46 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 11 Nov 2014 17:46:05 +0000 (17:46 +0000)
src/apprentice.c

index 1824a182192e04a527a1a13aff1f892ec8da93ef..6085bfb2816edf54df4653839dca0d3c3b5802ca 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.221 2014/10/29 14:41:32 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.222 2014/11/11 17:46:05 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -564,19 +564,19 @@ mlist_alloc(void)
 private void
 mlist_free(struct mlist *mlist)
 {
-       struct mlist *ml;
+       struct mlist *ml, *next;
 
        if (mlist == NULL)
                return;
 
-       for (ml = mlist->next; ml != mlist;) {
-               struct mlist *next = ml->next;
+       ml = mlist->next;
+       for (ml = mlist->next; (next = ml->next) != NULL; ml = next) {
                if (ml->map)
                        apprentice_unmap(ml->map);
                free(ml);
-               ml = next;
+               if (ml == mlist)
+                       break;
        }
-       free(ml);
 }
 
 #ifndef COMPILE_ONLY