From 989f1bf266536e1c66949e686e9b40a614e47f8c Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Tue, 28 Oct 2014 22:09:57 +0000 Subject: [PATCH] PR/395: Avoid infinite loop in oomem cleanup. --- src/apprentice.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/apprentice.c b/src/apprentice.c index 8279971d..4de8f6de 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.216 2014/09/24 19:49:07 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.217 2014/10/15 12:39:21 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; } -- 2.40.0