]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Lua_tcp: Sigh, another try to fix `close` invocation
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 21 Oct 2022 09:41:10 +0000 (10:41 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 21 Oct 2022 09:41:10 +0000 (10:41 +0100)
src/lua/lua_tcp.c

index 82d6af0ee39d49386cde69d469926b94b2a9cb1c..2ea3affa60720bada75bd6c563f29ead0cbc881e 100644 (file)
@@ -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 {