Skip to content

Commit 66a255a

Browse files
committed
Add a cleanup for copying closures. Closes #804.
1 parent 9a5e980 commit 66a255a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/comp/middle/trans.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6387,6 +6387,9 @@ fn trans_closure(bcx_maybe: &option::t[@block_ctxt],
63876387

63886388
let closure = create_real_fn_pair(env.bcx, option::get(llfnty),
63896389
llfndecl, env.ptr);
6390+
if copying {
6391+
add_clean_temp(bcx, closure, node_id_type(cx.ccx, id))
6392+
}
63906393
some({fn_pair: closure, bcx: env.bcx})
63916394
}
63926395
_ { none }

src/test/run-pass/lambda-no-leak.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Make sure we don't leak lambdas in silly ways.
2+
fn force(f: &fn()) { f() }
3+
fn main() {
4+
let x = 7;
5+
lambda() { log_err x; };
6+
force(lambda() { log_err x; });
7+
}

0 commit comments

Comments
 (0)