Skip to content

Commit ff2ffa9

Browse files
committed
fix: wrap tts_create in catch_unwind to prevent abort on engine panic
1 parent 0f92542 commit ff2ffa9

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ fn set_error(msg: &str) {
9393
pub extern "C" fn tts_create(
9494
engine_id: *const c_char,
9595
credentials_json: *const c_char,
96+
) -> *mut tts_ctx {
97+
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
98+
tts_create_inner(engine_id, credentials_json)
99+
}));
100+
match result {
101+
Ok(ptr) => ptr,
102+
Err(_) => {
103+
set_error("engine creation panicked");
104+
ptr::null_mut()
105+
}
106+
}
107+
}
108+
109+
fn tts_create_inner(
110+
engine_id: *const c_char,
111+
credentials_json: *const c_char,
96112
) -> *mut tts_ctx {
97113
if engine_id.is_null() {
98114
set_error("engine_id is null");

0 commit comments

Comments
 (0)