From 7a2d336d52dc17b4e9f27a3f100e79339e7e4b2d Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 18 Aug 2023 19:15:16 -0700 Subject: [PATCH] [wpinet] Leak multicast handles during windows shutdown (#5550) Destructing either of the multicast objects during process shutdown will result in a crash due to attempting to start a task on the non-existent thread pool. Solve this by just leaking all the handles upon destruction of the static multicast manager. This won't solve the case where the user statically allocates the object, but solves Java and C access, and most cases wouldn't be statically allocating the service announcer anyway in C++. --- .../src/main/native/cpp/MulticastHandleManager.cpp | 14 ++++++++++++++ .../src/main/native/cpp/MulticastHandleManager.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/wpinet/src/main/native/cpp/MulticastHandleManager.cpp b/wpinet/src/main/native/cpp/MulticastHandleManager.cpp index d249a1c6a9..ab44da895a 100644 --- a/wpinet/src/main/native/cpp/MulticastHandleManager.cpp +++ b/wpinet/src/main/native/cpp/MulticastHandleManager.cpp @@ -10,3 +10,17 @@ MulticastHandleManager& wpi::GetMulticastManager() { static MulticastHandleManager manager; return manager; } + +#ifdef _WIN32 +MulticastHandleManager::~MulticastHandleManager() { + // Multicast handles cannot be safely destructed on windows during shutdown. + // Just leak all handles. + for (auto&& i : resolvers) { + i.second.release(); + } + + for (auto&& i : announcers) { + i.second.release(); + } +} +#endif diff --git a/wpinet/src/main/native/cpp/MulticastHandleManager.h b/wpinet/src/main/native/cpp/MulticastHandleManager.h index 8c070f74a6..9925e84ff0 100644 --- a/wpinet/src/main/native/cpp/MulticastHandleManager.h +++ b/wpinet/src/main/native/cpp/MulticastHandleManager.h @@ -20,6 +20,9 @@ struct MulticastHandleManager { resolvers; wpi::DenseMap> announcers; +#ifdef _WIN32 + ~MulticastHandleManager(); +#endif }; MulticastHandleManager& GetMulticastManager();