async-thread: avoid closing eventfd twice

When employing eventfd for socketpair, there is only one file
descriptor. Closing that fd twice might result in fd corruption.
Thus, we should avoid closing the eventfd twice, following the
pattern in lib/multi.c.

Fixes #15725
Closes #15727
Reported-by: Christian Heusel
This commit is contained in:
Andy Pan 2024-12-12 12:48:56 +00:00 committed by Daniel Stenberg
parent aed732acb1
commit ff5091aa9f
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -195,9 +195,11 @@ void destroy_thread_sync_data(struct thread_sync_data *tsd)
* close one end of the socket pair (may be done in resolver thread); * close one end of the socket pair (may be done in resolver thread);
* the other end (for reading) is always closed in the parent thread. * the other end (for reading) is always closed in the parent thread.
*/ */
#ifndef USE_EVENTFD
if(tsd->sock_pair[1] != CURL_SOCKET_BAD) { if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
wakeup_close(tsd->sock_pair[1]); wakeup_close(tsd->sock_pair[1]);
} }
#endif
#endif #endif
memset(tsd, 0, sizeof(*tsd)); memset(tsd, 0, sizeof(*tsd));
} }