Skip to content

Commit a927ae3

Browse files
chyu313cfriedt
authored andcommitted
net: lib: sockets: Fix assertion failure when zsock_close()
When zsock_close() is called, socket is freed before the mutex for the socket is unlocked. If the freed socket is given to another thread immediately, the mutex for the socket will be initialized by the new socket owner, while the mutex is still locked by the thread calling zosck_close(). Fixes zephyrproject-rtos#36568 Signed-off-by: Chih Hung Yu <[email protected]>
1 parent 13b2e5b commit a927ae3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

subsys/net/lib/sockets/sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ int z_impl_zsock_close(int sock)
279279

280280
NET_DBG("close: ctx=%p, fd=%d", ctx, sock);
281281

282-
z_free_fd(sock);
283-
284282
ret = vtable->fd_vtable.close(ctx);
285283

286284
k_mutex_unlock(lock);
287285

286+
z_free_fd(sock);
287+
288288
return ret;
289289
}
290290

0 commit comments

Comments
 (0)