mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/vfs_sock_select_race_v4.3' into 'release/v4.3'
vfs: Fix potential select() race if both sock and other-fd trigger (v4.3) See merge request espressif/esp-idf!18176
This commit is contained in:
commit
c8882c2ba5
@ -1006,8 +1006,16 @@ int esp_vfs_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds
|
||||
if (ret >= 0) {
|
||||
ret += set_global_fd_sets(vfs_fds_triple, vfs_count, readfds, writefds, errorfds);
|
||||
}
|
||||
if (sel_sem.is_sem_local && sel_sem.sem) {
|
||||
vSemaphoreDelete(sel_sem.sem);
|
||||
if (sel_sem.sem) { // Cleanup the select semaphore
|
||||
if (sel_sem.is_sem_local) {
|
||||
vSemaphoreDelete(sel_sem.sem);
|
||||
} else if (socket_select) {
|
||||
SemaphoreHandle_t *s = sel_sem.sem;
|
||||
/* Select might have been triggered from both lwip and vfs fds at the same time, and
|
||||
* we have to make sure that the lwip semaphore is cleared when we exit select().
|
||||
* It is safe, as the semaphore belongs to the calling thread. */
|
||||
xSemaphoreTake(*s, 0);
|
||||
}
|
||||
sel_sem.sem = NULL;
|
||||
}
|
||||
free(vfs_fds_triple);
|
||||
|
Loading…
Reference in New Issue
Block a user