plugin-amb: explicitly restore Lua stack across callbacks.
authorKrisztian Litkey <krisztian.litkey@intel.com>
Tue, 28 Oct 2014 12:51:49 +0000 (14:51 +0200)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Thu, 8 Jan 2015 16:37:18 +0000 (18:37 +0200)
Change-Id: I6c20435fde7bd25842b1e673e31b5e1bae23d086

src/plugins/plugin-amb.c

index 6d95d20..2248fad 100644 (file)
@@ -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)