This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 03/N] Just another set of memory leaks


Hi.

There are new fixed for memory leaks, where the following:

==19826== 21 bytes in 1 blocks are definitely lost in loss record 16 of 625
==19826==    at 0x4C2A00F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19826==    by 0x16868D7: xmalloc (xmalloc.c:148)
==19826==    by 0x167FDFB: concat (concat.c:147)
==19826==    by 0x932920: gcc::dump_manager::get_dump_file_name(dump_file_info*) const (dumpfile.c:292)
==19826==    by 0x932821: gcc::dump_manager::get_dump_file_name(int) const (dumpfile.c:253)
==19826==    by 0xC1BBEA: pass_init_dump_file(opt_pass*) (passes.c:2074)
==19826==    by 0xC1C31B: execute_one_pass(opt_pass*) (passes.c:2302)
==19826==    by 0xC1D25E: execute_ipa_pass_list(opt_pass*) (passes.c:2735)
==19826==    by 0x8EED23: symbol_table::compile() (cgraphunit.c:2411)
==19826==    by 0x8EEF93: symbol_table::finalize_compilation_unit() (cgraphunit.c:2540)
==19826==    by 0xD205EE: compile_file() (toplev.c:491)
==19826==    by 0xD229AF: do_compile() (toplev.c:1954)

happens in context:

(gdb) p dump_file_name
$1 = 0x23e46d0 "ipa-pta-1.c.067i.pta"
(gdb) c
Continuing.

Breakpoint 2, pass_init_dump_file (pass=0x238c7c0) at ../../gcc/passes.c:2074
2074	      dump_file_name = dumps->get_dump_file_name (pass->static_pass_number);
(gdb) bt
#0  pass_init_dump_file (pass=0x238c7c0) at ../../gcc/passes.c:2074
#1  0x0000000000c1bebe in execute_one_ipa_transform_pass (node=0x7ffff6a01450, ipa_pass=0x238c7c0) at ../../gcc/passes.c:2172
#2  0x0000000000c1c07f in execute_all_ipa_transforms () at ../../gcc/passes.c:2223
#3  0x00000000008e39e0 in cgraph_node::get_body (this=0x7ffff6a01450) at ../../gcc/cgraph.c:3299
#4  0x0000000000f1469f in ipa_pta_execute () at ../../gcc/tree-ssa-structalias.c:7344
#5  0x0000000000f15465 in (anonymous namespace)::pass_ipa_pta::execute (this=0x238cb50) at ../../gcc/tree-ssa-structalias.c:7664
#6  0x0000000000c1c384 in execute_one_pass (pass=0x238cb50) at ../../gcc/passes.c:2316
#7  0x0000000000c1d25f in execute_ipa_pass_list (pass=0x238cb50) at ../../gcc/passes.c:2735
#8  0x00000000008eed24 in symbol_table::compile (this=0x7ffff68d30a8) at ../../gcc/cgraphunit.c:2411
#9  0x00000000008eef94 in symbol_table::finalize_compilation_unit (this=0x7ffff68d30a8) at ../../gcc/cgraphunit.c:2540
#10 0x0000000000d205ef in compile_file () at ../../gcc/toplev.c:491
#11 0x0000000000d229b0 in do_compile () at ../../gcc/toplev.c:1954
#12 0x0000000000d22c2f in toplev::main (this=0x7fffffffd910, argc=23, argv=0x7fffffffda18) at ../../gcc/toplev.c:2061
#13 0x0000000001619ad4 in main (argc=23, argv=0x7fffffffda18) at ../../gcc/main.c:39

Rest should be quite obvious.

Bootstrap and regression tests have been running.

Ready to install after it finishes?
Martin
>From 96dfceff2522b352d465016b48da4ea42e9e3ffc Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 10 Nov 2015 17:32:31 +0100
Subject: [PATCH 1/2] Fix various memory leaks

gcc/ChangeLog:

2015-11-11  Martin Liska  <mliska@suse.cz>

	* 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.
---
 gcc/gimple-ssa-strength-reduction.c |  3 +--
 gcc/passes.c                        | 19 ++++++++++++++-----
 gcc/tree-sra.c                      |  4 ++--
 gcc/var-tracking.c                  |  2 +-
 4 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gcc/gimple-ssa-strength-reduction.c b/gcc/gimple-ssa-strength-reduction.c
index ce32ad3..b807823 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<tree> 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<tree> 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 7a10cb6..dd8d00a 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 30aee19..2835c99 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 388b534..9185bfd 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.6.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]