From 29cae7e2fa770c39323adc4e13c534bcdd86d43a Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Thu, 5 Sep 2019 14:59:33 +0300 Subject: [PATCH] net: tcp: Cleanup context if connection is not established If we are closing connection before the connection was established, then unref the context so that the cleanup is done properly. Signed-off-by: Jukka Rissanen --- subsys/net/ip/tcp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index e6b2d3ad787..badd59e3f09 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -1402,6 +1402,11 @@ int net_tcp_put(struct net_context *context) return 0; } + if (context->tcp && + net_tcp_get_state(context->tcp) == NET_TCP_SYN_SENT) { + net_context_unref(context); + } + return -ENOTCONN; }