Skip to content

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

@labyrinth-ssr

Description

@labyrinth-ssr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions