1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 20:27:13 +01:00

Include a guard in the object iteration helper to avoid leaking in case of exception.

This commit is contained in:
Sandu Liviu Catalin 2017-06-19 14:24:10 +03:00
parent 641fa973e0
commit 5fa97e17d9

View File

@ -512,16 +512,18 @@ public:
template<class F>
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;
}
// Pop the null iterator and the object
sq_pop(vm,2);
}
}
protected:
/// @cond DEV