From 60cd39a5a8ce4ea0f1b6ca33d1c99aa6a780e713 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Sat, 20 Jun 2026 01:26:24 +1000 Subject: flow, udp: Fix errno handling in udp_flow_sock() flowside_connect() behaves much like connect(2) itself, returning -1 on error with errno set to the error code. One of the callers, in udp_flow_sock(), uses the errno code with flow_dbg_perror() *after* it's called epoll_del() and close() either of which could clobber errno. Fix that by moving the debug message earlier: there's no reason it has to wait until the epoll_del() and close(). While we're at it, adjust the comment on flowside_connect() to clarify that it sets errno (rather than, say, returning an error code). Suggested-by: Stefano Brivio Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- flow.c | 2 +- udp_flow.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flow.c b/flow.c index b296339..85ac630 100644 --- a/flow.c +++ b/flow.c @@ -258,7 +258,7 @@ int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif, * * Connect @s to the endpoint address and port from @tgt. * - * Return: 0 on success, negative on error + * Return: 0 on success, negative on error (setting errno) */ int flowside_connect(const struct ctx *c, int s, uint8_t pif, const struct flowside *tgt) diff --git a/udp_flow.c b/udp_flow.c index 35417bc..31e2f8a 100644 --- a/udp_flow.c +++ b/udp_flow.c @@ -90,11 +90,11 @@ static int udp_flow_sock(const struct ctx *c, if (flowside_connect(c, s, pif, side) < 0) { rc = -errno; + flow_dbg_perror(uflow, "Couldn't connect flow socket"); epoll_del(flow_epollfd(&uflow->f), s); close(s); - flow_dbg_perror(uflow, "Couldn't connect flow socket"); return rc; } uflow->s[sidei] = s; -- cgit v1.2.3