From b4d9f1aa07f229a29ae518bf67721acc92ee43ad Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 21 Apr 2019 12:03:31 -0300 Subject: [PATCH] Fix Context issue --- src/lib.rs | 8 ++++++-- 1 file 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 = 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 = hook.upgrade().unwrap().replace(None); + } EAT_NONE }, libc::c_int::min_value()))); ph.skip_pri_ck = false;