From c81897872d9e448830b0e2cc520fef538eeb347c Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 11 Nov 2015 12:21:44 +0100 Subject: [PATCH] Fix various memory leaks * gimple-ssa-strength-reduction.c (create_phi_basis): Use auto_vec. * passes.c (release_dump_file_name): New function. (pass_init_dump_file): Used from this function. (pass_fini_dump_file): Likewise. * tree-sra.c (convert_callers_for_node): Use xstrdup_for_dump. * var-tracking.c (vt_initialize): Use pool_allocator. From-SVN: r230152 --- gcc/ChangeLog | 10 ++++++++++ gcc/gimple-ssa-strength-reduction.c | 3 +-- gcc/passes.c | 19 ++++++++++++++----- gcc/tree-sra.c | 4 ++-- gcc/var-tracking.c | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ad69a402d51..13ed0d8256c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2015-11-11 Martin Liska + + * gimple-ssa-strength-reduction.c (create_phi_basis): + Use auto_vec. + * passes.c (release_dump_file_name): New function. + (pass_init_dump_file): Used from this function. + (pass_fini_dump_file): Likewise. + * tree-sra.c (convert_callers_for_node): Use xstrdup_for_dump. + * var-tracking.c (vt_initialize): Use pool_allocator. + 2015-11-11 Richard Biener Jiong Wang diff --git a/gcc/gimple-ssa-strength-reduction.c b/gcc/gimple-ssa-strength-reduction.c index ce32ad33e94..b8078230f34 100644 --- a/gcc/gimple-ssa-strength-reduction.c +++ b/gcc/gimple-ssa-strength-reduction.c @@ -2226,12 +2226,11 @@ create_phi_basis (slsr_cand_t c, gimple *from_phi, tree basis_name, int i; tree name, phi_arg; gphi *phi; - vec phi_args; slsr_cand_t basis = lookup_cand (c->basis); int nargs = gimple_phi_num_args (from_phi); basic_block phi_bb = gimple_bb (from_phi); slsr_cand_t phi_cand = base_cand_from_table (gimple_phi_result (from_phi)); - phi_args.create (nargs); + auto_vec phi_args (nargs); /* Process each argument of the existing phi that represents conditionally-executed add candidates. */ diff --git a/gcc/passes.c b/gcc/passes.c index 7a10cb6334c..dd8d00ad36a 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -2058,6 +2058,18 @@ verify_curr_properties (function *fn, void *data) gcc_assert ((fn->curr_properties & props) == props); } +/* Release dump file name if set. */ + +static void +release_dump_file_name (void) +{ + if (dump_file_name) + { + free (CONST_CAST (char *, dump_file_name)); + dump_file_name = NULL; + } +} + /* Initialize pass dump file. */ /* This is non-static so that the plugins can use it. */ @@ -2071,6 +2083,7 @@ pass_init_dump_file (opt_pass *pass) gcc::dump_manager *dumps = g->get_dumps (); bool initializing_dump = !dumps->dump_initialized_p (pass->static_pass_number); + release_dump_file_name (); dump_file_name = dumps->get_dump_file_name (pass->static_pass_number); dumps->dump_start (pass->static_pass_number, &dump_flags); if (dump_file && current_function_decl) @@ -2098,11 +2111,7 @@ pass_fini_dump_file (opt_pass *pass) timevar_push (TV_DUMP); /* Flush and close dump file. */ - if (dump_file_name) - { - free (CONST_CAST (char *, dump_file_name)); - dump_file_name = NULL; - } + release_dump_file_name (); g->get_dumps ()->dump_finish (pass->static_pass_number); timevar_pop (TV_DUMP); diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 30aee19aae7..2835c993588 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -4996,9 +4996,9 @@ convert_callers_for_node (struct cgraph_node *node, if (dump_file) fprintf (dump_file, "Adjusting call %s/%i -> %s/%i\n", - xstrdup (cs->caller->name ()), + xstrdup_for_dump (cs->caller->name ()), cs->caller->order, - xstrdup (cs->callee->name ()), + xstrdup_for_dump (cs->callee->name ()), cs->callee->order); ipa_modify_call_arguments (cs, cs->call_stmt, *adjustments); diff --git a/gcc/var-tracking.c b/gcc/var-tracking.c index 388b5348e5b..9185bfd39cf 100644 --- a/gcc/var-tracking.c +++ b/gcc/var-tracking.c @@ -9814,7 +9814,7 @@ vt_initialize (void) alloc_aux_for_blocks (sizeof (variable_tracking_info)); - empty_shared_hash = new shared_hash; + empty_shared_hash = shared_hash_pool.allocate (); empty_shared_hash->refcount = 1; empty_shared_hash->htab = new variable_table_type (1); changed_variables = new variable_table_type (10); -- 2.30.2