]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/bindings: fixed event callback not clearing the stack
authorMarek Vavruša <marek.vavrusa@nic.cz>
Mon, 25 May 2015 10:15:05 +0000 (12:15 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Mon, 25 May 2015 11:49:18 +0000 (13:49 +0200)
daemon/bindings.c
daemon/ffimodule.c

index f69f01675d457b8a87758c689b7d92b282bdca1c..6bde1f1538054f71edb4fe32dbcab51fd0f6df30 100644 (file)
@@ -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);
index 5232dbb91f9a9981116ec372f81857ee338b393e..92a2ea6632eaf3bf758a49c47ec947f87e4d56e9 100644 (file)
@@ -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;
 }