Skip to content

Commit c923f2a

Browse files
jukkargithub-actions[bot]
authored andcommitted
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: Jukka Rissanen <[email protected]> (cherry picked from commit 909710b)
1 parent dc88506 commit c923f2a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

subsys/net/ip/net_context.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,13 @@ int net_context_get(sa_family_t family, enum net_sock_type type, uint16_t proto,
616616
k_sem_give(&contexts_lock);
617617

618618
if (ret < 0) {
619+
if (ret == -EADDRINUSE &&
620+
!net_if_is_ip_offloaded(net_if_get_default()) &&
621+
proto == IPPROTO_TCP) {
622+
/* Free the TCP context that we allocated earlier */
623+
net_tcp_put(&contexts[i]);
624+
}
625+
619626
return ret;
620627
}
621628

0 commit comments

Comments
 (0)