net/context: Close TCP connection properly

Closing a connection, thus calling net_context_put() will not close a
TCP connection properly, and will leak tcp connection memory.

This is because: net_context_put calls net_context_unref which calls
net_tcp_unref which leads to unref tcp connection and thus sets
ctx->tcp to NULL. Back to net_context_put, that one finally calls
net_tcp_put: but that bails out directly since ctx->tcp is NULL.

Fixing it by inverting net_tcp_put() and net_context_unref() calls
within net_context_put().

Fixes #38598

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c
index 3c0e75d..c82304c 100644
--- a/subsys/net/ip/net_context.c
+++ b/subsys/net/ip/net_context.c
@@ -411,12 +411,12 @@
 	context->recv_cb = NULL;
 	context->send_cb = NULL;
 
-	/* Decrement refcount on user app's behalf */
-	net_context_unref(context);
-
 	/* net_tcp_put() will handle decrementing refcount on stack's behalf */
 	net_tcp_put(context);
 
+	/* Decrement refcount on user app's behalf */
+	net_context_unref(context);
+
 unlock:
 	k_mutex_unlock(&context->lock);