From c5ff6a4703ccf54f3f18371dcbe79bb4b91fe066 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 22 Dec 2011 17:05:45 +0100 Subject: [PATCH] plug memory leaks --- ir/adt/pdeq.c | 6 ++---- ir/be/becopyheur4.c | 7 +++++-- ir/be/beifg.c | 2 +- ir/opt/ldstopt.c | 4 ++-- ir/opt/loop.c | 2 ++ ir/opt/opt_inline.c | 2 ++ 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ir/adt/pdeq.c b/ir/adt/pdeq.c index 2ae50822b..cc168460e 100644 --- a/ir/adt/pdeq.c +++ b/ir/adt/pdeq.c @@ -73,9 +73,8 @@ struct pdeq { /** * cache of unused, pdeq blocks to speed up new_pdeq and del_pdeq. - * +1 for compilers that can't grok empty arrays */ -static pdeq *pdeq_block_cache[TUNE_NSAVED_PDEQS+1]; +static pdeq *pdeq_block_cache[TUNE_NSAVED_PDEQS]; /** * Number of pdeqs in pdeq_store. @@ -107,7 +106,7 @@ static inline void free_pdeq_block (pdeq *p) static inline pdeq *alloc_pdeq_block (void) { pdeq *p; - if (TUNE_NSAVED_PDEQS && pdeqs_cached) { + if (pdeqs_cached > 0) { p = pdeq_block_cache[--pdeqs_cached]; } else { p = (pdeq*) xmalloc(PREF_MALLOC_SIZE); @@ -157,7 +156,6 @@ void del_pdeq(pdeq *dq) qq = q->r; free_pdeq_block(q); } while ((q = qq)); - } /* Checks if a list is empty. */ diff --git a/ir/be/becopyheur4.c b/ir/be/becopyheur4.c index 31995381c..ad5ca80d0 100644 --- a/ir/be/becopyheur4.c +++ b/ir/be/becopyheur4.c @@ -1243,7 +1243,7 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c) */ for (i = 0; i < env->k; ++i) { int col = order[i].col; - waitq *good_starts = new_waitq(); + waitq *good_starts; aff_chunk_t *local_best; int n_succeeded; @@ -1254,6 +1254,7 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c) DB((dbg, LEVEL_2, "\ttrying color %d\n", col)); n_succeeded = 0; + good_starts = new_waitq(); /* try to bring all nodes of given chunk to the current color. */ for (idx = 0, len = ARR_LEN(c->n); idx < len; ++idx) { @@ -1292,8 +1293,10 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c) } /* try next color when failed */ - if (n_succeeded == 0) + if (n_succeeded == 0) { + del_waitq(good_starts); continue; + } /* fragment the chunk according to the coloring */ local_best = fragment_chunk(env, col, c, tmp_chunks); diff --git a/ir/be/beifg.c b/ir/be/beifg.c index e7a7c7a9c..e59faa6d9 100644 --- a/ir/be/beifg.c +++ b/ir/be/beifg.c @@ -186,7 +186,7 @@ ir_node *be_ifg_neighbours_begin(const be_ifg_t *ifg, neighbours_iter_t *iter, const ir_node *irn) { find_neighbours(ifg, iter, irn); - return ir_nodeset_iterator_next(&iter->iter); + return get_next_neighbour(iter); } ir_node *be_ifg_neighbours_next(neighbours_iter_t *iter) diff --git a/ir/opt/ldstopt.c b/ir/opt/ldstopt.c index 8ce2c7ec5..a396787e9 100644 --- a/ir/opt/ldstopt.c +++ b/ir/opt/ldstopt.c @@ -1831,8 +1831,6 @@ static void move_loads_out_of_loops(scc *pscc, loop_env *env) phi_entry *phi_list = NULL; set *avail; - avail = new_set(cmp_avail_entry, 8); - /* collect all outer memories */ for (phi = pscc->head; phi != NULL; phi = next) { node_entry *ne = get_irn_ne(phi, env); @@ -1866,6 +1864,8 @@ static void move_loads_out_of_loops(scc *pscc, loop_env *env) if (phi_list->next != NULL) return; + avail = new_set(cmp_avail_entry, 8); + for (load = pscc->head; load; load = next) { ir_mode *load_mode; node_entry *ne = get_irn_ne(load, env); diff --git a/ir/opt/loop.c b/ir/opt/loop.c index 8e7fae7e6..c0eb5de73 100644 --- a/ir/opt/loop.c +++ b/ir/opt/loop.c @@ -590,6 +590,8 @@ static void extend_irn(ir_node *n, ir_node *newnode, bool new_is_backedge) set_backedge(n, i); } } + free(ins); + free(bes); } /* Extends a block by a copy of its pred at pos, diff --git a/ir/opt/opt_inline.c b/ir/opt/opt_inline.c index ad135cd53..dfbb53967 100644 --- a/ir/opt/opt_inline.c +++ b/ir/opt/opt_inline.c @@ -1518,6 +1518,8 @@ static ir_graph **create_irg_list(void) callgraph_walk(NULL, callgraph_walker, &env); assert(n_irgs == env.last_irg); + free_callgraph(); + return env.irgs; } -- 2.20.1