Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
bblum opened this issue Aug 9, 2012 · 7 comments
Closed
Labels
A-linkage Area: linking into static, shared libraries and binaries A-testsuite Area: The testsuite used to check the correctness of rustc E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@bblum
Copy link
Contributor

bblum commented Aug 9, 2012

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.

@bblum
Copy link
Contributor Author

bblum commented Aug 9, 2012

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

@bblum
Copy link
Contributor Author

bblum commented Aug 18, 2012

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.

@bblum
Copy link
Contributor Author

bblum commented Aug 18, 2012

More minimal still:

#[test]
fn crash() {
    let x = ~~5;
    util::ignore(x);
}

@catamorphism
Copy link
Contributor

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

@bblum
Copy link
Contributor Author

bblum commented Dec 7, 2012

bummer we never figured out what it was

@catamorphism
Copy link
Contributor

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

@bblum
Copy link
Contributor Author

bblum commented Dec 7, 2012

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). ;)

saethlin pushed a commit to saethlin/rust that referenced this issue Nov 17, 2023
freebsd adding getentropy interception support
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Addresses the new `AggregateKind::RawPtr` added in
rust-lang#123840.

Resolves rust-lang#3161 

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.

---------

Co-authored-by: Kareem Khazem <karkhaz@amazon.com>
Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-testsuite Area: The testsuite used to check the correctness of rustc E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

2 participants