Skip to content

Commit 7a2d336

Browse files
authored
[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++.
1 parent f9e2757 commit 7a2d336

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

wpinet/src/main/native/cpp/MulticastHandleManager.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ MulticastHandleManager& wpi::GetMulticastManager() {
1010
static MulticastHandleManager manager;
1111
return manager;
1212
}
13+
14+
#ifdef _WIN32
15+
MulticastHandleManager::~MulticastHandleManager() {
16+
// Multicast handles cannot be safely destructed on windows during shutdown.
17+
// Just leak all handles.
18+
for (auto&& i : resolvers) {
19+
i.second.release();
20+
}
21+
22+
for (auto&& i : announcers) {
23+
i.second.release();
24+
}
25+
}
26+
#endif

wpinet/src/main/native/cpp/MulticastHandleManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ struct MulticastHandleManager {
2020
resolvers;
2121
wpi::DenseMap<size_t, std::unique_ptr<wpi::MulticastServiceAnnouncer>>
2222
announcers;
23+
#ifdef _WIN32
24+
~MulticastHandleManager();
25+
#endif
2326
};
2427

2528
MulticastHandleManager& GetMulticastManager();

0 commit comments

Comments
 (0)