Skip to content

Commit 68a334f

Browse files
fix(netwatch): cancel Windows callbacks before dropping Arc
1 parent f3986e3 commit 68a334f

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

netwatch/src/netmon/windows.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ impl CallbackHandler {
129129
handle: UnicastCallbackHandle,
130130
) -> Result<(), Error> {
131131
trace!("unregistering unicast callback");
132-
if self
133-
.unicast_callbacks
134-
.remove(&(handle.0.0 as isize))
135-
.is_some()
136-
{
132+
let key = handle.0.0 as isize;
133+
if self.unicast_callbacks.contains_key(&key) {
134+
// Cancel first to ensure no in-flight callbacks reference the Arc,
135+
// then remove the Arc from the map.
137136
unsafe {
138137
windows::Win32::NetworkManagement::IpHelper::CancelMibChangeNotify2(handle.0)
139138
.ok()?;
140139
}
140+
self.unicast_callbacks.remove(&key);
141141
}
142142

143143
Ok(())
@@ -171,15 +171,15 @@ impl CallbackHandler {
171171
handle: RouteCallbackHandle,
172172
) -> Result<(), Error> {
173173
trace!("unregistering route callback");
174-
if self
175-
.route_callbacks
176-
.remove(&(handle.0.0 as isize))
177-
.is_some()
178-
{
174+
let key = handle.0.0 as isize;
175+
if self.route_callbacks.contains_key(&key) {
176+
// Cancel first to ensure no in-flight callbacks reference the Arc,
177+
// then remove the Arc from the map.
179178
unsafe {
180179
windows::Win32::NetworkManagement::IpHelper::CancelMibChangeNotify2(handle.0)
181180
.ok()?;
182181
}
182+
self.route_callbacks.remove(&key);
183183
}
184184

185185
Ok(())

0 commit comments

Comments
 (0)