summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-04-18 03:21:29 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-04-18 03:21:29 -0300
commit273201648d3432410567da623cf803f2a26f156c (patch)
tree8e0ab52cd0c72a2a0a05ea290e9952d999be6948
parentad35c9f8aac015a073127780cfb2e515bdae2fb4 (diff)
Use leaking to avoid panics at FFI boundaries
-rw-r--r--src/lib.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9371275..a4ef9e9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -474,6 +474,8 @@ unsafe fn call_hook_protected<F: FnOnce() -> Eat + UnwindSafe>(
                 hexchat_print_str(ph, &s, false);
             } else if let Some(s) = e.downcast_ref::<Cow<'static, str>>() {
                 hexchat_print_str(ph, &s, false);
+            } else {
+                mem::forget(e);
             }
             EAT_NONE
         }
@@ -1725,8 +1727,9 @@ pub unsafe fn hexchat_plugin_init<'ph, T>(plugin_handle: LtPhPtr<'ph>,
             1
         },
         r @ _ => {
-            if let Err(_) = r {
+            if let Err(e) = r {
                 // TODO try to log panic?
+                mem::forget(e);
             }
             0
         },
@@ -1745,7 +1748,7 @@ pub unsafe fn hexchat_plugin_deinit<'ph, T>(plugin_handle: LtPhPtr<'ph>) -> c_in
                 let mut info: Option<PluginInfo> = None;
                 {
                     let mut ausinfo = AssertUnwindSafe(&mut info);
-                    safe_to_unload = if catch_unwind(move || {
+                    safe_to_unload = match catch_unwind(move || {
                         let mut userdata = pop_userdata(plugin_handle);
                         let pluginfo = userdata.pluginfo;
                         userdata.plug.as_mut().deinit(&mut PluginHandle::new(plugin_handle, pluginfo, Rc::clone(&userdata.contexts)));
@@ -1758,7 +1761,13 @@ pub unsafe fn hexchat_plugin_deinit<'ph, T>(plugin_handle: LtPhPtr<'ph>) -> c_in
                         // we return 0 mostly as a hint that something went
                         // wrong, than anything else.
                         // we do deliberately leak pluginfo on panic, also.
-                    }).is_ok() { 1 } else { 0 };
+                    }) {
+                        Ok(_) => 1,
+                        Err(e) => {
+                            mem::forget(e);
+                            0
+                        }
+                    };
                 }
                 if let Some(mut info) = info {
                     info.drop_info();