jingfei195887 opened a new pull request, #21686:
URL: https://github.com/apache/nuttx/pull/21686
## Summary
`epoll_do_close()` decrements `crefs` under `eph->lock` but releases
the lock before testing it. When the last two references to an epoll
instance (for example an fd and its `dup()`) are closed at the same
time, both threads can read `crefs <= 0` after the unlock. Both then
walk the lists and free the epoll head, or one frees it while the other
is still using it.
Test the count and tear down the lists while holding the lock, and
destroy the lock only after the teardown.
## Impact
No change for a single close. Concurrent closes of the last references
no longer free the epoll head twice.
## Testing
Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master
03aea78639, `sim:nsh`.
- A small test program creates an epoll instance watching a pipe, dups
it twice, checks `epoll_wait()`, and closes the last two references
from two threads, 50 times. `epoll_wait()` succeeds in all 50 rounds
and the heap does not grow, on both master and this PR. The race needs
two CPUs, so the single-core sim does not hit it; the test only checks
that close and teardown still work.
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- Make and CMake builds pass; `ostest` exits with status 0.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]