[patch] lcm.c: Fix memory leaks - Part 1/2

Kazu Hirata kazu@cs.umass.edu
Sat Dec 11 21:44:00 GMT 2004


Hi,

Attached is a patch to fix memory leaks.

These "insert" and "delete" seem to be local to the "for" loop shown
in the second hunk of this patch because they are allocated every time
pre_edge_lcm is called.

The problem is that when the "for" loop loops twice or more, we
allocate "insert" and "delete" without freeing them, so the old
pointers to the two bitmaps are lost.

The patch allocates and frees "insert" and "delete" in the "for" loop.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-12-11  Kazu Hirata  <kazu@cs.umass.edu>

	* lcm.c (optimize_mode_switching): Free insert and delete in
	the "for" loop.

Index: lcm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/lcm.c,v
retrieving revision 1.67
diff -u -d -p -r1.67 lcm.c
--- lcm.c	30 Sep 2004 23:40:15 -0000	1.67
+++ lcm.c	11 Dec 2004 02:51:59 -0000
@@ -858,8 +858,6 @@ struct bb_info
 static sbitmap *antic;
 static sbitmap *transp;
 static sbitmap *comp;
-static sbitmap *delete;
-static sbitmap *insert;
 
 static struct seginfo * new_seginfo (int, rtx, int, HARD_REG_SET);
 static void add_seginfo (struct bb_info *, struct seginfo *);
@@ -1138,6 +1136,8 @@ optimize_mode_switching (FILE *file)
   for (i = 0; i < max_num_modes; i++)
     {
       int current_mode[N_ENTITIES];
+      sbitmap *delete;
+      sbitmap *insert;
 
       /* Set the anticipatable and computing arrays.  */
       sbitmap_vector_zero (antic, last_basic_block);
@@ -1248,6 +1248,8 @@ optimize_mode_switching (FILE *file)
 	      }
 	}
 
+      sbitmap_vector_free (delete);
+      sbitmap_vector_free (insert);
       clear_aux_for_edges ();
       free_edge_list (edge_list);
     }
@@ -1298,8 +1300,6 @@ optimize_mode_switching (FILE *file)
   sbitmap_vector_free (antic);
   sbitmap_vector_free (transp);
   sbitmap_vector_free (comp);
-  sbitmap_vector_free (delete);
-  sbitmap_vector_free (insert);
 
   if (need_commit)
     commit_edge_insertions ();



More information about the Gcc-patches mailing list