Skip to content

Commit d64c8b6

Browse files
authored
looper: Also abort on panic in FFI callback (#421)
As with #412 we shouldn't let panics unwind into the FFI boundary; use the new helper `abort_on_panic()` utility to catch these and abort the process instead.
1 parent 574aee0 commit d64c8b6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ndk/src/looper.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use std::ptr;
1818
use std::time::Duration;
1919
use thiserror::Error;
2020

21+
use crate::utils::abort_on_panic;
22+
2123
/// A thread-local native [`ALooper *`]. This promises that there is a looper associated with the
2224
/// current thread.
2325
///
@@ -309,14 +311,14 @@ impl ForeignLooper {
309311
_events: i32,
310312
data: *mut c_void,
311313
) -> i32 {
312-
unsafe {
314+
abort_on_panic(|| unsafe {
313315
let mut cb = ManuallyDrop::new(Box::<F>::from_raw(data as *mut _));
314316
let keep_registered = cb(BorrowedFd::borrow_raw(fd));
315317
if !keep_registered {
316318
ManuallyDrop::into_inner(cb);
317319
}
318320
keep_registered as i32
319-
}
321+
})
320322
}
321323
let data = Box::into_raw(Box::new(callback)) as *mut _;
322324
match unsafe {

0 commit comments

Comments
 (0)