]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Avoid TCP leak on read without write
authorDmitriy Alekseev <1865999+dragoangel@users.noreply.github.com>
Wed, 20 May 2026 12:39:08 +0000 (14:39 +0200)
committerDmitriy Alekseev <1865999+dragoangel@users.noreply.github.com>
Wed, 20 May 2026 12:39:08 +0000 (14:39 +0200)
Signed-off-by: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com>
src/lua/lua_tcp.c

index dd6dc7af04ea763ab4b6a2d259d94cb7ee67c422..fe7e3f145287696d0613e5abbb006e5e95fb9e99 100644 (file)
@@ -1201,6 +1201,16 @@ lua_tcp_handler(int fd, short what, gpointer ud)
                        r = read(cbd->fd, inbuf, sizeof(inbuf));
                }
 
+               /*
+                * Read-only requests never receive an EV_WRITE for connect-complete
+                * detection, so CONNECTED would otherwise stay unset and the
+                * downstream FINISHED|CONNECTED gates on conn:close() leak refcounts.
+                * Gating on r > 0 keeps pre-byte errors routed to on_error.
+                */
+               if (r > 0 && !(cbd->flags & LUA_TCP_FLAG_CONNECTED)) {
+                       cbd->flags |= LUA_TCP_FLAG_CONNECTED;
+               }
+
                lua_tcp_process_read(cbd, inbuf, r);
        }
        else if (what == EV_WRITE) {