Skip to content

rt::Allocation doesn't alert on double-free #384

@abonander

Description

@abonander

Looking through the implementation of loom::alloc::Track and rt::Allocation, I was surprised to see that it apparently doesn't alert on a double-free:

loom/src/rt/alloc.rs

Lines 68 to 80 in dbf32b0

impl Drop for Allocation {
#[track_caller]
fn drop(&mut self) {
let location = location!();
rt::execution(|execution| {
let state = self.state.get_mut(&mut execution.objects);
trace!(state = ?self.state, drop.location = %location, "Allocation::drop");
state.is_dropped = true;
});
}
}

It looks like if a user is directly calling dealloc(), that would catch a double-free, but with a potentially unhelpful panic message:

None => panic!("pointer not tracked"),

I'm wondering if there's a reason why checking for double-frees was omitted, or if this is just an oversight. It seems like a whole class of possible bugs is being overlooked here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions