summary refs log tree commit diff stats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ac34340..444753e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1272,8 +1272,12 @@ unsafe fn wrap_context(ph: &mut PluginHandle, ctx: *const internals::HexchatCont
     let hook = std::panic::AssertUnwindSafe(Rc::downgrade(&closure)); // dropping the Context should drop the Closure
     ph.skip_pri_ck = true;
     closure.set(Some(ph.hook_print("Close Context", move |ph, _| {
-        let _ = &ctxp;
-        let _: Option<PrintHookHandle> = hook.upgrade().unwrap().replace(None);
+        // need to be careful not to recurse or leak memory
+        let ph = ph.ph;
+        let ctx = ((*ph).hexchat_get_context)(ph);
+        if **ctxp == ctx {
+            let _: Option<PrintHookHandle> = hook.upgrade().unwrap().replace(None);
+        }
         EAT_NONE
     }, libc::c_int::min_value())));
     ph.skip_pri_ck = false;