Skip to content

Commit 989499c

Browse files
jukkardkalowsk
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 6eebe0a commit 989499c

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
@@ -634,6 +634,13 @@ int net_context_get(sa_family_t family, enum net_sock_type type, uint16_t proto,
634634
k_sem_give(&contexts_lock);
635635

636636
if (ret < 0) {
637+
if (ret == -EADDRINUSE &&
638+
!net_if_is_ip_offloaded(net_if_get_default()) &&
639+
proto == IPPROTO_TCP) {
640+
/* Free the TCP context that we allocated earlier */
641+
net_tcp_put(&contexts[i]);
642+
}
643+
637644
return ret;
638645
}
639646

0 commit comments

Comments
 (0)