]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Fix memory leak in do-while loop
authorHaitao Li <lihaitao@gmail.com>
Sun, 4 Dec 2011 16:33:25 +0000 (00:33 +0800)
committerHaitao Li <lihaitao@gmail.com>
Sun, 4 Dec 2011 16:38:38 +0000 (00:38 +0800)
Issue #1257

src/comp/middle/trans.rs
src/test/run-pass/issue-1257.rs [new file with mode: 0644]

index 6a70d9e109deb313e360397d1e69a7d661ea8abc..7d52316d9a8a8c16d0404657d67af472e362e871 100644 (file)
@@ -2844,8 +2844,11 @@ fn trans_do_while(cx: @block_ctxt, body: ast::blk, cond: @ast::expr) ->
         new_loop_scope_block_ctxt(cx, option::none::<@block_ctxt>, next_cx,
                                   "do-while loop body");
     let body_end = trans_block(body_cx, body);
-    let cond_res = trans_temp_expr(body_end, cond);
-    CondBr(cond_res.bcx, cond_res.val, body_cx.llbb, next_cx.llbb);
+    let cond_cx = new_scope_block_ctxt(body_cx, "do-while cond");
+    Br(body_end, cond_cx.llbb);
+    let cond_res = trans_temp_expr(cond_cx, cond);
+    let cond_bcx = trans_block_cleanups(cond_res.bcx, cond_cx);
+    CondBr(cond_bcx, cond_res.val, body_cx.llbb, next_cx.llbb);
     Br(cx, body_cx.llbb);
     ret next_cx;
 }
diff --git a/src/test/run-pass/issue-1257.rs b/src/test/run-pass/issue-1257.rs
new file mode 100644 (file)
index 0000000..1ec446d
--- /dev/null
@@ -0,0 +1,8 @@
+fn main () {
+  let line = "";
+  let i = 0;
+  do {
+    line = if i == 9 { "exit" } else { "notexit" };
+    i += 1;
+  } while line != "exit";
+}