From 663b684fea4f314ac4451e65264bbdb9265ce1ae Mon Sep 17 00:00:00 2001 From: Daniel Nejezchleb Date: Fri, 14 Apr 2023 23:36:57 +0200 Subject: [PATCH] net: socket: fix hanging net contexts Calls put instead of unref on net contexts in the socket accept function. Mere unref didn't subtract the reference count of net context which leaves it in used state. This situation happens in case of accepting already closed connection. Signed-off-by: Daniel Nejezchleb --- subsys/net/lib/sockets/sockets.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index b923fa38f64..16d6e879f86 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -615,7 +615,7 @@ int zsock_accept_ctx(struct net_context *parent, struct sockaddr *addr, sock_set_eof(ctx); z_free_fd(fd); zsock_flush_queue(ctx); - net_context_unref(ctx); + net_context_put(ctx); errno = ECONNABORTED; return -1; } @@ -625,7 +625,7 @@ int zsock_accept_ctx(struct net_context *parent, struct sockaddr *addr, errno = ECONNABORTED; z_free_fd(fd); zsock_flush_queue(ctx); - net_context_unref(ctx); + net_context_put(ctx); return -1; } @@ -647,7 +647,7 @@ int zsock_accept_ctx(struct net_context *parent, struct sockaddr *addr, z_free_fd(fd); errno = ENOTSUP; zsock_flush_queue(ctx); - net_context_unref(ctx); + net_context_put(ctx); return -1; } }