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

Segfault when casting owned structs to owned traits (double free?) #6318

Closed
bstrie opened this issue May 8, 2013 · 6 comments
Closed

Segfault when casting owned structs to owned traits (double free?) #6318

bstrie opened this issue May 8, 2013 · 6 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@bstrie
Copy link
Contributor

bstrie commented May 8, 2013

This compiles, but segfaults when run:

pub enum Thing {
    A(~Foo)
}

pub trait Foo {}

pub struct Struct;

impl Foo for Struct {}

fn main() {
    match A(~Struct as ~Foo) {
        A(a) => 0,
    };
}

The segfault goes away when you do the following:

  • Convert A(a) => 0 to A(_) => 0
  • Change all the unique pointers to managed pointers
  • Change the tag from A(~Foo) to A(~Struct) (and remove the cast)
@wilkie
Copy link

wilkie commented May 16, 2013

I've been looking at this one as I originally discovered it. I've been looking in the wrong place though... it is not just sum-types, but any cast of a unique struct to a unique trait. This also segfaults:

pub trait Foo {}

pub struct Struct;

impl Foo for Struct {}

fn func(thing: ~Foo) {}

fn main() {
  let a = ~Struct as ~Foo;
  let b = func(a);
}

It segfaults on a glue_drop function in both examples. I'm not too certain about the invariants of the takes and drops. I'm assuming they are done in mirror. Is it dropping something twice by mistake?

@bstrie
Copy link
Contributor Author

bstrie commented May 17, 2013

Good catch, I've updated the title.

@emberian
Copy link
Member

emberian commented Aug 5, 2013

This no longer segfaults; needs a testcase.

@emberian
Copy link
Member

emberian commented Aug 5, 2013

(well, testcases arleady exist, just need their way into the suite)

@wilkie
Copy link

wilkie commented Aug 5, 2013

@cmr yay! that's awesome. :) I'll try and pull the fixed code and try it out with my original breaking code later today.

bors added a commit that referenced this issue Aug 15, 2013
Closes #3907
Closes #5493
Closes #4464
Closes #4759
Closes #5666
Closes #5884
Closes #5926
Closes #6318
Closes #6557
Closes #6898
Closes #6919
Closes #7222
@wilkie
Copy link

wilkie commented Aug 16, 2013

Awesome. All of the cases I came up with all compile and run as expected. Thanks. :)

flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 20, 2020
…shearth

Use article_and_description for missing docs

Moves closer to the current rustc missing_doc lint

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants