Skip to content

glibc malloc/free crash with destructors and util::ignore, only in coretest. #3161

Closed

Description

@bblum

Write mod crash; in libcore/core.rc, and add libcore/crash.rs:

#[test]
fn make_crash() {
    struct defer {
        x: &~(); 
        new(x: &~()) { self.x = x; }
        drop { // Get rid of the destructor and it doesn't crash.
        }
    }   
    let x = ~();
    // If you just write let z = defer(~~()) it doesn't crash.
    let z = defer(&x);
    // If you just write util::ignore(defer(x)) it doesn't crash.
    util::ignore(z);
    // If you write "pure fn ignore<T>(+_x: T) { }" (i.e., exactly the same as
    // it is in util) and call that instead, it doesn't crash.
}   

Then make check-stage0-core.

Backtrace:

#3  0x00007ffff671a626 in malloc_printerr (action=3, str="free(): invalid pointer", ptr=<optimized out>)
#4  0x00007ffff6f9800d in __morestack ()
#5  0x00007ffff6f87028 in call_on_c_stack (fn_ptr=0x7ffff6f85e80, args=0x7fffec101330, this=0x7fffe8105a50)
#6  call_upcall_on_c_stack (fn_ptr=0x7ffff6f85e80, args=0x7fffec101330, task=<optimized out>)
#7  upcall_exchange_free (ptr=<optimized out>)
#8  0x0000000000540107 in __test::tests::anon ()
#9  0x00007ffff768f581 in task::spawn_raw::make_child_wrapper::anon ()
#10 0x00007ffff76d8d3c in __morestack ()
#11 0x00007ffff6f84564 in task_start_wrapper (a=0x7fffe81068a0)

For the life of me I could not get it to work outside of coretest. I tried std and I tried in its own module. Probably this means it's related to #2912.

Activity

  1. bblum commented on Aug 9, 2012

    @bblum
    ContributorAuthor

    Disassembly of __test::tests::anon: http://pastebin.mozilla.org/1745826

  2. bblum commented on Aug 18, 2012

    @bblum
    ContributorAuthor

    More minimal:

    #[test]
    fn crash() {
        struct X {
            x: ~~int;
            drop {
                error!("freeing %d", **self.x);
            }
        }
        let x = X { x: ~~5 };
        util::ignore(x);
    }
    

    The destructor just doesn't run.

  3. bblum commented on Aug 18, 2012

    @bblum
    ContributorAuthor

    More minimal still:

    #[test]
    fn crash() {
        let x = ~~5;
        util::ignore(x);
    }
    
  4. catamorphism commented on Dec 7, 2012

    @catamorphism
    Contributor

    This appears to be fixed as of b60a0be (I only tried the most minimal test case).

  5. bblum commented on Dec 7, 2012

    @bblum
    ContributorAuthor

    bummer we never figured out what it was

  6. catamorphism commented on Dec 7, 2012

    @catamorphism
    Contributor

    You're welcome to check out a revision where it doesn't work and try to find the bug :-D

  7. bblum commented on Dec 7, 2012

    @bblum
    ContributorAuthor

    you misunderstand; I am lamenting that the Bug Fairy never came along and told us the story out of the blue (with proverbial free lunch also provided). ;)

  8. added a commit that references this issue on Nov 17, 2023
  9. added a commit that references this issue on Jun 4, 2024
    997a54c
  10. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesA-testsuiteArea: The testsuite used to check the correctness of rustcE-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions