Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloaded assignment operators can leak memory #2581

Closed
eholk opened this issue Jun 13, 2012 · 1 comment
Closed

Overloaded assignment operators can leak memory #2581

eholk opened this issue Jun 13, 2012 · 1 comment
Labels
A-codegen Area: Code generation

Comments

@eholk
Copy link
Contributor

eholk commented Jun 13, 2012

It seems to involve pointers... Here's a test case with several examples and non-examples.

impl methods<T: copy> for [T] {
    fn -(x: [T]/&) -> [T] {
        [x[0], x[0], x[0]]
    }

    fn foo(x: [T]/&) -> [T] {
        [x[0], x[0], x[0]]
    }
}

impl methods<T: copy> for ~T {
    fn +(rhs: ~T) -> ~T {
        rhs
    }
}

impl methods for ~int {
    fn -(rhs: ~int) -> ~int {
        ~(*self - *rhs)
    }
}

fn main() {
    // leaks
    let mut bar = [1, 2, 3];
    bar -= [3, 2, 1];
    bar -= [4, 5, 6];

    io::println(#fmt("%?", bar));

    // okay
    let mut bar = [1, 2, 3];
    bar = bar.foo([3, 2, 1]);
    bar = bar.foo([4, 5, 6]);

    io::println(#fmt("%?", bar));

    // okay
    let mut bar = [1, 2, 3];
    bar = bar - [3, 2, 1];
    bar = bar - [4, 5, 6];

    io::println(#fmt("%?", bar));

    // Leaks
    let mut bar = ~1;
    bar += ~2;
    bar += ~3;

    io:: println(#fmt("%?", bar));

    // Leaks
    let mut bar = ~1;
    bar -= ~2;
    bar -= ~3;

    io:: println(#fmt("%?", bar));
}
@eholk
Copy link
Contributor Author

eholk commented Jun 13, 2012

This problem is also present with @int, but they show up as an unreclaimed object in the cycle collector.

@ghost ghost assigned eholk Jun 13, 2012
eholk added a commit to eholk/rust that referenced this issue Jun 13, 2012
eholk added a commit to eholk/rust that referenced this issue Jun 14, 2012
@eholk eholk closed this as completed Jun 21, 2012
@eholk eholk removed their assignment Jun 16, 2014
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
This removes dependency on atty, and tracing-tree (which depends on atty). This is in response to this security advisory:

https://rustsec.org/advisories/RUSTSEC-2021-0145

atty is removed by switching to std::io::IsTerminal. tracing-tree is removed by replacing HierarchicalLayer with a regular tracing_subscriber::fmt::layer that directs to stderr.

The PR also updates hermit-abi to 0.3.2 from 0.3.1, in response to 0.3.1 being yanked.

This PR resolves rust-lang#2580.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

No branches or pull requests

1 participant