From: Christos Zoulas Date: Tue, 28 Oct 2014 22:09:57 +0000 (+0000) Subject: PR/395: Avoid infinite loop in oomem cleanup. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8211dbd4ee0f516c45a0437647c7b314966071f6;p=file PR/395: Avoid infinite loop in oomem cleanup. --- diff --git a/src/apprentice.c b/src/apprentice.c index d2628956..21dfa6b4 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.217 2014/10/15 12:39:21 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.218 2014/10/28 22:09:57 christos Exp $") #endif /* lint */ #include "magic.h" @@ -593,11 +593,9 @@ buffer_apprentice(struct magic_set *ms, struct magic **bufs, mlist_free(ms->mlist[i]); if ((ms->mlist[i] = mlist_alloc()) == NULL) { file_oomem(ms, sizeof(*ms->mlist[i])); - if (i != 0) { - --i; - do - mlist_free(ms->mlist[i]); - while (i != 0); + while (i-- > 0) { + mlist_free(ms->mlist[i]); + ms->mlist[i] = NULL; } return -1; }