Commit 2f5f0df2 authored by Jukka Rissanen's avatar Jukka Rissanen Committed by github-actions[bot]
Browse files

net: context: Make sure TCP allocation is not leaked



If we have allocated a TCP connection, and if after that
we get an error like EADDRINUSE, then we must de-allocate
the TCP connection otherwise there is a buffer leak.

Signed-off-by: default avatarJukka Rissanen <jukka.rissanen@nordicsemi.no>
(cherry picked from commit 909710b5)
parent cccd5048
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -553,6 +553,13 @@ int net_context_get(sa_family_t family, enum net_sock_type type, uint16_t proto,
	k_sem_give(&contexts_lock);

	if (ret < 0) {
		if (ret == -EADDRINUSE &&
		    !net_if_is_ip_offloaded(net_if_get_default()) &&
		    proto == IPPROTO_TCP) {
			/* Free the TCP context that we allocated earlier */
			net_tcp_put(&contexts[i]);
		}

		return ret;
	}