@@ -247,29 +247,32 @@ impl SCNetworkReachability {
247
247
248
248
let mut callback_context = SCNetworkReachabilityContext {
249
249
version : 0 ,
250
- info : Arc :: as_ptr ( & callback) as * mut _ ,
250
+ info : Arc :: into_raw ( callback) as * mut _ ,
251
251
retain : Some ( NetworkReachabilityCallbackContext :: < F > :: retain_context) ,
252
252
release : Some ( NetworkReachabilityCallbackContext :: < F > :: release_context) ,
253
253
copyDescription : Some ( NetworkReachabilityCallbackContext :: < F > :: copy_ctx_description) ,
254
254
} ;
255
255
256
- if unsafe {
257
- // The call to SCNetworkReachabilitySetCallback will call the
258
- // `retain` callback which will increment the reference count on
259
- // `callback`. Therefore, although `callback` is dropped when this
260
- // function goes out of scope, the reference count will still be >0.
261
- //
262
- // When `SCNetworkReachability` is dropped, `release` is called
263
- // which will drop the reference count on `callback` to 0.
264
- //
265
- // Assumes the pointer pointed to by the `info` member of `callback_context` is still valid.
256
+ let result = unsafe {
266
257
SCNetworkReachabilitySetCallback (
267
258
self . 0 ,
268
259
Some ( NetworkReachabilityCallbackContext :: < F > :: callback) ,
269
260
& mut callback_context,
270
261
)
271
- } == 0u8
272
- {
262
+ } ;
263
+
264
+ // The call to SCNetworkReachabilitySetCallback will call the
265
+ // `retain` callback which will increment the reference count on
266
+ // `callback`. Therefore, although the count is decremented below,
267
+ // the reference count will still be >0.
268
+ //
269
+ // When `SCNetworkReachability` is dropped, `release` is called
270
+ // which will drop the reference count on `callback` to 0.
271
+ //
272
+ // Assumes the pointer pointed to by the `info` member of `callback_context` is still valid.
273
+ unsafe { Arc :: decrement_strong_count ( callback_context. info ) } ;
274
+
275
+ if result == 0u8 {
273
276
Err ( SetCallbackError { } )
274
277
} else {
275
278
Ok ( ( ) )
0 commit comments