Task that outlives root task leaks memory
$ cat ~/tmp/test2.rs
fn child2(str s) {
}
fn main() {
spawn child2("hi");
}
$ ./rustboot -L . ~/tmp/test2.rs -o ~/tmp/test2 && ~/tmp/test2
rt: fatal, 'leaked memory in rust main loop (1 objects)' failed, rt/rust.cpp:32
Passing an int instead of a str (as spawn.rs does) doesn't leak, and having the main thread yield several times (as spawn-fn.rs does) allows the child to exit, which also avoids the leak.
This is because the task fails to unwind correctly if it's never executed. Here child2() never gets a chance to start before it is killed by main(). At this point the task's stack is in an inconsistent state which confuses the unwind glue. The frame pointer should be in the right place, and the frame_glue_fns should be initialized.
The unwind glue fails to drop the reference to the string, thus causing a leak.
Michael Bebenita at 2010-08-10 21:53:32
My memory of the case I reduced this from indicates that "outliving" also causes leaks, not just "never starting". But that could be obsolete. I'll try to produce a test case along those lines after "never started" is fixed.
Jeffrey Yasskin at 2010-08-10 23:42:47
I'll try to add support for putting tasks to sleep, should make these types of bugs easier to explore.
Michael Bebenita at 2010-08-10 23:54:00
WONTFIX (not required for bootstrapping, also likely to change semantics when tasking is implemented in rustc)
Graydon Hoare at 2011-01-27 01:00:34