Skip to content

Root count overflows in mem::forget loop, leading to erroneous drop #34

Closed
@apasel422

Description

@apasel422

Running the following in release mode causes a segfault:

extern crate gc;

use gc::Gc;
use std::{mem, usize};

fn main() {
    let a = Gc::new("abc".to_string());
    let a2 = a.clone();

    for _ in 0..usize::MAX {
        mem::forget(a.clone());
    }

    drop(a2);
    gc::force_collect();
    println!("{:?}", *a);
}

This is the same issue that was fixed in rust-lang/rust#27174. I have a fix incoming.

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