[OpenWrt-Devel] [PATCH 4/5] Fix bug of unref resources in Lua binding; fd method delete -> cancel.

xfguo at credosemi.com xfguo at credosemi.com
Fri Jun 20 07:31:20 EDT 2014


Signed-off-by: Xiongfei(Alex) Guo <xfguo at credosemi.com>
---
 examples/uloop-example.lua |  2 +-
 lua/uloop.c                | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/examples/uloop-example.lua b/examples/uloop-example.lua
index 9b0684e..ab85a5d 100755
--- a/examples/uloop-example.lua
+++ b/examples/uloop-example.lua
@@ -50,7 +50,7 @@ udp_ev = uloop.fd_add(udp, function(ufd, events)
 	local words, msg_or_ip, port_or_nil = ufd:receivefrom()
 	print('Recv UDP packet from '..msg_or_ip..':'..port_or_nil..' : '..words)
 	if words == "Stop!" then
-		udp_ev:delete()
+		udp_ev:cancel()
 	end
 end, uloop.ULOOP_READ)
 
diff --git a/lua/uloop.c b/lua/uloop.c
index df57b8a..319942c 100644
--- a/lua/uloop.c
+++ b/lua/uloop.c
@@ -80,7 +80,7 @@ static int ul_timer_free(lua_State *L)
 
 	uloop_timeout_cancel(&tout->t);
 	lua_getglobal(state, "__uloop_cb");
-	luaL_unref(L, -1, tout->r);
+	luaL_unref(state, -1, tout->r);
 
 	return 1;
 }
@@ -177,16 +177,20 @@ static int ul_ufd_delete(lua_State *L)
 	struct lua_uloop_fd *ufd = lua_touserdata(L, 1);
 
 	uloop_fd_delete(&ufd->fd);
+
 	lua_getglobal(state, "__uloop_cb");
-	luaL_unref(L, -1, ufd->r);
+	luaL_unref(state, -1, ufd->r);
+	lua_remove(state, -1);
+
 	lua_getglobal(state, "__uloop_fds");
-	luaL_unref(L, -1, ufd->fd_r);
+	luaL_unref(state, -1, ufd->fd_r);
+	lua_remove(state, -1);
 
 	return 1;
 }
 
 static const luaL_Reg ufd_m[] = {
-	{ "delete", ul_ufd_delete },
+	{ "cancel", ul_ufd_delete },
 	{ NULL, NULL }
 };
 
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list