commit 075fa9f: [Fix] Lua_tcp: Sigh, another try to fix `close` invocation

Vsevolod Stakhov vsevolod at rspamd.com
Fri Oct 21 09:42:07 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-10-21 10:41:10 +0100
URL: https://github.com/rspamd/rspamd/commit/075fa9fb2dd9b8e0c2fe9758a93502c124a005e2 (HEAD -> master)

[Fix] Lua_tcp: Sigh, another try to fix `close` invocation

---
 src/lua/lua_tcp.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

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 {


More information about the Commits mailing list