From 01bb972ce51444b3b815eaed5f5d1748b34a67bc Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Tue, 28 Oct 2014 14:51:49 +0200 Subject: [PATCH] plugin-amb: explicitly restore Lua stack across callbacks. Change-Id: I6c20435fde7bd25842b1e673e31b5e1bae23d086 --- src/plugins/plugin-amb.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/plugins/plugin-amb.c b/src/plugins/plugin-amb.c index 6d95d20..2248fad 100644 --- a/src/plugins/plugin-amb.c +++ b/src/plugins/plugin-amb.c @@ -795,6 +795,7 @@ error: static void lua_property_handler(mrp_dbus_msg_t *msg, dbus_property_watch_t *w) { + int top; #if 0 char *variant_sig = NULL; #endif @@ -841,6 +842,8 @@ static void lua_property_handler(mrp_dbus_msg_t *msg, dbus_property_watch_t *w) } #endif + top = lua_gettop(w->ctx->L); + /* load the function pointer to the stack */ lua_rawgeti(w->ctx->L, LUA_REGISTRYINDEX, w->lua_prop->handler_ref); @@ -855,6 +858,8 @@ static void lua_property_handler(mrp_dbus_msg_t *msg, dbus_property_watch_t *w) mrp_log_error("AMB: failed to call Lua handler function"); } + lua_settop(w->ctx->L, top); + mrp_dbus_msg_exit_container(msg); end: @@ -1489,15 +1494,21 @@ error: static int load_config(lua_State *L, const char *path) { + int success, top; + + top = lua_gettop(L); + if (!luaL_loadfile(L, path) && !lua_pcall(L, 0, 0, 0)) - return TRUE; + success = TRUE; else { mrp_log_error("AMB: failed to load config file %s.", path); mrp_log_error("%s", lua_tostring(L, -1)); - lua_settop(L, 0); - - return FALSE; + success = FALSE; } + + lua_settop(L, top); + + return success; } static int unsubscribe_signal_cb(void *key, void *object, void *user_data) -- 2.7.4