diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2025-05-14 10:35:58 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2025-05-14 12:45:54 +0200 |
| commit | be7802a6aed590c0f23e5dfe7be003aaa868a42b (patch) | |
| tree | d1348cff07fcf6e7a6728f8442422935ea770c5b /mullvad-ios/src/api_client | |
| parent | 98c30cb6a37e8f92a5353e3554116bbff7054f73 (diff) | |
| download | mullvadvpn-be7802a6aed590c0f23e5dfe7be003aaa868a42b.tar.xz mullvadvpn-be7802a6aed590c0f23e5dfe7be003aaa868a42b.zip | |
Make the API cancellation handle safe, and properly clear out pointers
Diffstat (limited to 'mullvad-ios/src/api_client')
| -rw-r--r-- | mullvad-ios/src/api_client/cancellation.rs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/mullvad-ios/src/api_client/cancellation.rs b/mullvad-ios/src/api_client/cancellation.rs index 5ea2c902c1..4c86919e2d 100644 --- a/mullvad-ios/src/api_client/cancellation.rs +++ b/mullvad-ios/src/api_client/cancellation.rs @@ -21,7 +21,7 @@ impl SwiftCancelHandle { /// This call is safe as long as the pointer is only ever used from a single thread and the /// instance of `SwiftCancelHandle` was created with a valid pointer to /// `RequestCancelHandle`. - unsafe fn into_handle(mut self) -> RequestCancelHandle { + unsafe fn as_handle(&mut self) -> RequestCancelHandle { // SAFETY: See safety notes above let handle = unsafe { *Box::from_raw(self.ptr) }; self.ptr = null_mut(); @@ -61,16 +61,15 @@ impl RequestCancelHandle { /// /// # Safety /// -/// `handle_ptr` must be pointing to a valid instance of `SwiftCancelHandle`. This function -/// is not safe to call multiple times with the same `SwiftCancelHandle`. +/// `handle_ptr` must be pointing to a valid instance of `SwiftCancelHandle`. #[no_mangle] -extern "C" fn mullvad_api_cancel_task(handle_ptr: SwiftCancelHandle) { +extern "C" fn mullvad_api_cancel_task(handle_ptr: &mut SwiftCancelHandle) { if handle_ptr.ptr.is_null() { return; } - // SAFETY: See notes for `into_handle` - let handle = unsafe { handle_ptr.into_handle() }; + // SAFETY: See notes for `as_handle` + let handle = unsafe { handle_ptr.as_handle() }; handle.cancel() } @@ -79,14 +78,13 @@ extern "C" fn mullvad_api_cancel_task(handle_ptr: SwiftCancelHandle) { /// /// # Safety /// -/// `handle_ptr` must be pointing to a valid instance of `SwiftCancelHandle`. This function -/// is not safe to call multiple times with the same `SwiftCancelHandle`. +/// `handle_ptr` must be pointing to a valid instance of `SwiftCancelHandle`. #[no_mangle] -extern "C" fn mullvad_api_cancel_task_drop(handle_ptr: SwiftCancelHandle) { +extern "C" fn mullvad_api_cancel_task_drop(handle_ptr: &mut SwiftCancelHandle) { if handle_ptr.ptr.is_null() { return; } - // SAFETY: See notes for `into_handle` - let _handle = unsafe { handle_ptr.into_handle() }; + // SAFETY: See notes for `as_handle` + let _handle = unsafe { handle_ptr.as_handle() }; } |
