得られたエラー:
$ rustc leakyFunction.rs --test
$ ./leakyFunction
running 1 test
test testForLeakage ... Unreclaimed object found at 0xb6d02d98: ((), (10))
leaked memory in rust main loop (1 objects)
leakyFunction: /home/havvy/rust/src/rt/memory_region.cpp:172:
memory_region::~memory_region(): Assertion `false' failed.
Aborted (core dumped)
さびたコード (縮小されたテストケース):
use std;
type boxedFn = { theFn: fn () -> uint };
fn createClosure (closedUint: uint) -> boxedFn {
{ theFn: fn@ () -> uint { closedUint } }
}
#[test]
fn testForLeakage () {
let aFn: boxedFn = createClosure(10);
let myInt: uint = aFn.theFn();
assert myInt == 10;
}
なぜこのメモリリークが発生するのですか?