vorner / signal-hook

Rust library allowing to register multiple handlers for the same signal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Calling init multiple times will leak AtomicPtr in slot with thread panicking.

labyrinth-ssr opened this issue · comments

fn init(&self, slot: &Self::Storage, _: c_int) {
let new = Box::default();
let old = slot.0.swap(Box::into_raw(new), Ordering::Release);
// We leak the pointer on purpose here. This is invalid state anyway and must not happen,
// but if it still does, we can't drop that while some other thread might still be having
// the raw pointer.
assert!(old.is_null(), "Init called multiple times");
}

Noticed that if init is called multiple times, the code will panic.

Probable fix is like:
Use compare_and_exchange and only store the value when the slot.0 is null.

Hello

Can you explain why you think this is actually a bug? Calling init multiple times is invalid use and the crate doesn't use it that way. So why spend extra effort on supporting it?

I believe that while it would panic, that it still does not lead to UB or anything.