From: Marek VavruĊĦa Date: Mon, 25 May 2015 10:15:05 +0000 (+0200) Subject: daemon/bindings: fixed event callback not clearing the stack X-Git-Tag: v1.0.0-beta1~138 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d4e8a3338d4c5683a59e62216fed281b6b77467;p=thirdparty%2Fknot-resolver.git daemon/bindings: fixed event callback not clearing the stack --- diff --git a/daemon/bindings.c b/daemon/bindings.c index f69f01675..6bde1f153 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -440,8 +440,9 @@ static void event_callback(uv_timer_t *timer) int ret = engine_pcall(L, 1); if (ret != 0) { fprintf(stderr, "error: %s\n", lua_tostring(L, -1)); - lua_pop(L, 1); } + /* Clear the stack, there may be event a/o enything returned */ + lua_settop(L, 0); /* Free callback if not recurrent or an error */ if (ret != 0 || uv_timer_get_repeat(timer) == 0) { uv_close((uv_handle_t *)timer, (uv_close_cb) event_free); diff --git a/daemon/ffimodule.c b/daemon/ffimodule.c index 5232dbb91..92a2ea663 100644 --- a/daemon/ffimodule.c +++ b/daemon/ffimodule.c @@ -35,6 +35,7 @@ static inline lua_State *l_ffi_preface(struct kr_module *module, const char *cal lua_getfield(L, -1, call); lua_remove(L, -2); if (lua_isnil(L, -1)) { + lua_pop(L, 1); return NULL; } lua_pushlightuserdata(L, module); @@ -68,7 +69,7 @@ static int l_ffi_defer(lua_State *L) /** @internal Helper for calling the entrypoint. */ static inline int l_ffi_call(lua_State *L, int argc) { - int status = lua_pcall(L, argc, LUA_MULTRET, 0); + int status = lua_pcall(L, argc, 1, 0); if (status != 0) { fprintf(stderr, "error: %s\n", lua_tostring(L, -1)); lua_pop(L, 1); @@ -82,7 +83,7 @@ static inline int l_ffi_call(lua_State *L, int argc) } else if (lua_isnumber(L, -1)) { /* Return code */ status = lua_tonumber(L, 1); } - lua_pop(L, n); + lua_pop(L, 1); } return status; }