From ca452b744393b1cc78a123e6a4c27498b60429bf Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Tue, 16 Nov 2010 17:01:14 -0600
Subject: [PATCH] Fix memory leaks.
---
gcc/cfgloop.c | 1 +
gcc/tree-loop-flattening.c | 10 ++++++----
2 files changed, 7 insertions(+), 4 deletions(-)
@@ -1285,6 +1285,7 @@ cancel_loop (struct loop *loop)
for (i = 0; i < loop->num_nodes; i++)
bbs[i]->loop_father = outer;
+ free (bbs);
delete_loop (loop);
}
@@ -469,9 +469,7 @@ flatten_loop (loop_p loop, tree *scratch_pad)
mark_dfs_back_edges ();
bbs = get_loop_body (loop);
-
back_edges = VEC_alloc (edge, heap, 3);
- loop_body = VEC_alloc (basic_block, heap, 3);
for (i = 0; i < n; i++)
FOR_EACH_EDGE (e, ei, bbs[i]->succs)
@@ -484,9 +482,13 @@ flatten_loop (loop_p loop, tree *scratch_pad)
/* Early return and do not modify the code when there are no back
edges. */
if (VEC_empty (edge, back_edges))
- return 0;
+ {
+ VEC_free (edge, heap, back_edges);
+ return 0;
+ }
cancel_subloops (loop);
+ loop_body = VEC_alloc (basic_block, heap, VEC_length (edge, back_edges));
/* Split the latch edge to make sure that the latch basic block does
not contain code. */
@@ -501,7 +503,7 @@ flatten_loop (loop_p loop, tree *scratch_pad)
redirect_edge_and_branch_force (e, loop->latch);
/* Save the basic block where it was pointing. */
- VEC_safe_push (basic_block, heap, loop_body, dest);
+ VEC_quick_push (basic_block, loop_body, dest);
}
update_loop_phi_nodes (loop, pred_e);
--
1.7.0.4