<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div><pre style="line-height: 23.7999992370605px; width: 1146.640625px;">HI, all
this is a patch to fix libubox-lua's uloop.process gc bug:</pre><pre style="line-height: 23.7999992370605px; width: 1146.640625px;"> before free lua userdata <span style="font-family: Arial; line-height: 23.7999992370605px; white-space: normal;">proc, we may need to call </span><span style="font-family: Arial; line-height: 23.7999992370605px; white-space: normal;">uloop_process_delete first.</span></pre><pre style="line-height: 23.7999992370605px; width: 1146.640625px;"><br></pre><pre style="line-height: 23.7999992370605px; width: 1146.640625px;">
Best regards
Signed-off-by:Chen Bin <<a href="mailto:ewolfok@126.com" style="color: rgb(19, 129, 68);">ewolfok@126.com</a>>
---</pre></div><div>--- a/lua/uloop.c</div><div>+++ b/lua/uloop.c</div><div>@@ -77,9 +77,9 @@ static int ul_timer_set(lua_State *L)</div><div> static int ul_timer_free(lua_State *L)</div><div> {</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>struct lua_uloop_timeout *tout = lua_touserdata(L, 1);</div><div>-</div><div>+</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>uloop_timeout_cancel(&tout->t);</div><div>-</div><div>+</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>/* obj.__index.__gc = nil , make sure executing only once*/</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>lua_getfield(L, -1, "__index");</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushstring(L, "__gc");</div><div>@@ -181,7 +181,7 @@ static int get_sock_fd(lua_State* L, int</div><div> static int ul_ufd_delete(lua_State *L)</div><div> {</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>struct lua_uloop_fd *ufd = lua_touserdata(L, 1);</div><div>-</div><div>+</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>uloop_fd_delete(&ufd->fd);</div><div><br></div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>/* obj.__index.__gc = nil , make sure executing only once*/</div><div>@@ -263,6 +263,33 @@ static int ul_ufd_add(lua_State *L)</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>return 1;</div><div> }</div><div><br></div><div>+static int ul_process_delete(lua_State *L)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>struct lua_uloop_process *proc = lua_touserdata(L, 1);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* obj.__index.__gc = nil , make sure executing only once*/</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_getfield(L, -1, "__index");</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushstring(L, "__gc");</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushnil(L);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_settable(L, -3);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>if (proc->r != LUA_NOREF) {</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>uloop_process_delete(&proc->p);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_getglobal(state, "__uloop_cb");</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>luaL_unref(state, -1, proc->r);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_remove(state, -1);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return 1;</div><div>+}</div><div>+</div><div>+static const luaL_Reg uproc_m[] = {</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>{ "delete", ul_process_delete },</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>{ NULL, NULL }</div><div>+};</div><div>+</div><div>+</div><div> static void ul_process_cb(struct uloop_process *p, int ret)</div><div> {</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>struct lua_uloop_process *proc = container_of(p, struct lua_uloop_process, p);</div><div>@@ -271,6 +298,7 @@ static void ul_process_cb(struct uloop_p</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>lua_rawgeti(state, -1, proc->r);</div><div><br></div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>luaL_unref(state, -2, proc->r);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>proc->r = LUA_NOREF;</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>lua_remove(state, -2);</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushinteger(state, ret >> 8);</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>lua_call(state, 1, 0);</div><div>@@ -331,6 +359,18 @@ static int ul_process(lua_State *L)</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>ref = luaL_ref(L, -2);</div><div><br></div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>proc = lua_newuserdata(L, sizeof(*proc));</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_createtable(L, 0, 2);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushvalue(L, -1);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_setfield(L, -2, "__index");</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushcfunction(L, ul_process_delete);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_setfield(L, -2, "__gc");</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushvalue(L, -1);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_setmetatable(L, -3);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushvalue(L, -2);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>luaI_openlib(L, NULL, uproc_m, 1);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushvalue(L, -2);</div><div>+</div><div>+</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>memset(proc, 0, sizeof(*proc));</div><div><br></div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>proc->r = ref;</div></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>