From 5fa97e17d9b0a771191160c1544837e8492df12e Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 19 Jun 2017 14:24:10 +0300 Subject: [PATCH] Include a guard in the object iteration helper to avoid leaking in case of exception. --- include/sqrat/sqratObject.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/sqrat/sqratObject.h b/include/sqrat/sqratObject.h index e284bce2..72553c35 100644 --- a/include/sqrat/sqratObject.h +++ b/include/sqrat/sqratObject.h @@ -512,15 +512,17 @@ public: template void Foreach(F&& func) const { + const StackGuard sg(vm); sq_pushobject(vm,obj); sq_pushnull(vm); while(SQ_SUCCEEDED(sq_next(vm,-2))) { - func(vm); // -1 is the value and -2 is the key - sq_pop(vm,2); // Pop the key and value + if (!func(vm)) + { + return; + } + sq_pop(vm,2); } - // Pop the null iterator and the object - sq_pop(vm,2); } protected: