From: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com> Date: Wed, 20 May 2026 12:39:08 +0000 (+0200) Subject: [Fix] Avoid TCP leak on read without write X-Git-Tag: 4.1.0~40^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=24ab2ecfa4bcb68d71ba7d4185ac88b47b3c6a2a;p=thirdparty%2Frspamd.git [Fix] Avoid TCP leak on read without write Signed-off-by: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com> --- diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index dd6dc7af04..fe7e3f1452 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -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) {