Skip to content

Memory leak in Arc::make_mut with allocators #158875

Description

@maxdexh

See #155746

#![feature(allocator_api)]

#[test]
fn make_mut_leaks() {
    use std::alloc::Global;
    use std::rc::Rc;
    use std::sync::Arc;

    let alloc = Rc::new(Global);

    {
        let mut arc = Arc::new_in(123, alloc.clone());
        let weak = Arc::downgrade(&arc); // create a weak so make_mut steals the data
        _ = Arc::make_mut(&mut arc);
        assert_eq!(weak.upgrade(), None);
    }

    assert_eq!(Rc::strong_count(&alloc), 1); // if this is >1, we have a memory leak!
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsC-bugCategory: This is a bug.I-memleakIssue: Runtime memory leak without `mem::forget`.T-libsRelevant to the library team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions