···11+From ff5091aa9f73802e894b1cbdf24ab84e103200e2 Mon Sep 17 00:00:00 2001
22+From: Andy Pan <i@andypan.me>
33+Date: Thu, 12 Dec 2024 12:48:56 +0000
44+Subject: [PATCH] async-thread: avoid closing eventfd twice
55+66+When employing eventfd for socketpair, there is only one file
77+descriptor. Closing that fd twice might result in fd corruption.
88+Thus, we should avoid closing the eventfd twice, following the
99+pattern in lib/multi.c.
1010+1111+Fixes #15725
1212+Closes #15727
1313+Reported-by: Christian Heusel
1414+---
1515+ lib/asyn-thread.c | 2 ++
1616+ 1 file changed, 2 insertions(+)
1717+1818+diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c
1919+index a58e4b790494..32d496b107cb 100644
2020+--- a/lib/asyn-thread.c
2121++++ b/lib/asyn-thread.c
2222+@@ -195,9 +195,11 @@ void destroy_thread_sync_data(struct thread_sync_data *tsd)
2323+ * close one end of the socket pair (may be done in resolver thread);
2424+ * the other end (for reading) is always closed in the parent thread.
2525+ */
2626++#ifndef USE_EVENTFD
2727+ if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
2828+ wakeup_close(tsd->sock_pair[1]);
2929+ }
3030++#endif
3131+ #endif
3232+ memset(tsd, 0, sizeof(*tsd));
3333+ }
+6
pkgs/by-name/cu/curlMinimal/package.nix
···6363 hash = "sha256-x8p9tIsJCXQ+rvNCUNoCwZvGHU8dzt1mA/EJQJU2q1Y=";
6464 };
65656666+ # FIXME: avoid rebuilding darwin stdenv for now
6767+ patches = lib.optionals (!stdenv.isDarwin) [
6868+ # https://github.com/curl/curl/issues/15725
6969+ ./fix-eventfd-free.patch
7070+ ];
7171+6672 # this could be accomplished by updateAutotoolsGnuConfigScriptsHook, but that causes infinite recursion
6773 # necessary for FreeBSD code path in configure
6874 postPatch = ''