From: Vsevolod Stakhov Date: Fri, 21 Oct 2022 09:41:10 +0000 (+0100) Subject: [Fix] Lua_tcp: Sigh, another try to fix `close` invocation X-Git-Tag: 3.4~38 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=075fa9fb2dd9b8e0c2fe9758a93502c124a005e2;p=rspamd.git [Fix] Lua_tcp: Sigh, another try to fix `close` invocation --- diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 82d6af0ee..2ea3affa6 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -1044,6 +1044,11 @@ lua_tcp_process_read (struct lua_tcp_cbdata *cbd, } else { lua_tcp_push_error (cbd, TRUE, "IO read error: connection terminated"); + + if ((cbd->flags & LUA_TCP_FLAG_FINISHED)) { + /* A callback has called `close` method, so we need to release a refcount */ + TCP_RELEASE (cbd); + } } lua_tcp_plan_handler_event (cbd, FALSE, FALSE); @@ -1067,6 +1072,11 @@ lua_tcp_process_read (struct lua_tcp_cbdata *cbd, lua_tcp_push_error (cbd, TRUE, "IO read error while trying to read data: %s", strerror (errno)); + + if ((cbd->flags & LUA_TCP_FLAG_FINISHED)) { + /* A callback has called `close` method, so we need to release a refcount */ + TCP_RELEASE (cbd); + } } lua_tcp_plan_handler_event (cbd, FALSE, FALSE); @@ -1193,8 +1203,8 @@ lua_tcp_plan_handler_event (struct lua_tcp_cbdata *cbd, gboolean can_read, if (!(cbd->flags & LUA_TCP_FLAG_FINISHED)) { /* We are finished with a connection */ msg_debug_tcp ("no handlers left, finish session"); - TCP_RELEASE (cbd); cbd->flags |= LUA_TCP_FLAG_FINISHED; + TCP_RELEASE (cbd); } } else {