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]

plugging memory leaks


Some memory leaks I found while searching for the just-fixed
Haifa memory corruption.


r~


        * bitmap.h (BITMAP_XFREE): New.
        * flow.c (life_analysis): Use it.
        (life_analysis_1): Free blocks.

        * combine.c (undo_commit): New.
        (try_combine): Use it.  Don't zap undobuf.undos.
        (combine_instructions): Don't zap undobuf.undos; free the
        undobuf.frees list.

        * local-alloc.c (local_alloc): Free qty_phys_num_sugg.

        * stmt.c (cost_table_): New.
        (estimate_case_costs): Use it instead of xmalloc.

        * toplev.c (compile_file): Reuse dumpname memory instead
        of strdup'ing it.

Index: bitmap.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/bitmap.h,v
retrieving revision 1.15
diff -c -p -d -r1.15 bitmap.h
*** bitmap.h	1999/11/01 23:19:43	1.15
--- bitmap.h	1999/11/05 00:42:30
*************** extern void debug_bitmap PROTO((bitmap))
*** 119,131 ****
    bitmap_initialize ((bitmap) xmalloc (sizeof (bitmap_head)))
  
  /* Do any cleanup needed on a bitmap when it is no longer used.  */
! #define BITMAP_FREE(BITMAP)					\
! do {				\
!   if (BITMAP)			\
!     {				\
!       bitmap_clear (BITMAP);	\
!       (BITMAP) = 0;		\
!     }									\
  } while (0)
  
  /* Do any one-time initializations needed for bitmaps.  */
--- 119,142 ----
    bitmap_initialize ((bitmap) xmalloc (sizeof (bitmap_head)))
  
  /* Do any cleanup needed on a bitmap when it is no longer used.  */
! #define BITMAP_FREE(BITMAP)			\
! do {						\
!   if (BITMAP)					\
!     {						\
!       bitmap_clear (BITMAP);			\
!       (BITMAP) = 0;				\
!     }						\
! } while (0)
! 
! /* Do any cleanup needed on an xmalloced bitmap when it is no longer used.  */
! #define BITMAP_XFREE(BITMAP)			\
! do {						\
!   if (BITMAP)					\
!     {						\
!       bitmap_clear (BITMAP);			\
!       free (BITMAP);				\
!       (BITMAP) = 0;				\
!     }						\
  } while (0)
  
  /* Do any one-time initializations needed for bitmaps.  */
Index: combine.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/combine.c,v
retrieving revision 1.90
diff -c -p -d -r1.90 combine.c
*** combine.c	1999/11/01 22:42:01	1.90
--- combine.c	1999/11/05 00:42:31
*************** static int combinable_i3pat	PROTO((rtx, 
*** 361,366 ****
--- 361,367 ----
  static int contains_muldiv	PROTO((rtx));
  static rtx try_combine		PROTO((rtx, rtx, rtx));
  static void undo_all		PROTO((void));
+ static void undo_commit		PROTO((void));
  static rtx *find_split_point	PROTO((rtx *, rtx));
  static rtx subst		PROTO((rtx, rtx, rtx, int, int));
  static rtx combine_simplify_rtx	PROTO((rtx, enum machine_mode, int, int));
*************** combine_instructions (f, nregs)
*** 495,501 ****
    combine_merges = 0;
    combine_extras = 0;
    combine_successes = 0;
-   undobuf.undos = undobuf.previous_undos = 0;
  
    combine_max_regno = nregs;
  
--- 496,501 ----
*************** combine_instructions (f, nregs)
*** 717,722 ****
--- 717,732 ----
    free (reg_last_set_sign_bit_copies);
    free (uid_cuid);
  
+   {
+     struct undo *undo, *next;
+     for (undo = undobuf.frees; undo; undo = next)
+       {
+ 	next = undo->next;
+ 	free (undo);
+       }
+     undobuf.frees = 0;
+   }
+ 
    total_attempts += combine_attempts;
    total_merges += combine_merges;
    total_extras += combine_extras;
*************** try_combine (i3, i2, i1)
*** 1461,1468 ****
      return 0;
  
    combine_attempts++;
- 
-   undobuf.undos = undobuf.previous_undos = 0;
    undobuf.other_insn = 0;
  
    /* Save the current high-water-mark so we can free storage if we didn't
--- 1471,1476 ----
*************** try_combine (i3, i2, i1)
*** 2620,2625 ****
--- 2628,2634 ----
    }
  
    combine_successes++;
+   undo_commit ();
  
    /* Clear this here, so that subsequent get_last_value calls are not
       affected.  */
*************** undo_all ()
*** 2659,2664 ****
--- 2668,2691 ----
       affected.  */
    subst_prev_insn = NULL_RTX;
  }
+ 
+ /* We've committed to accepting the changes we made.  Move all
+    of the undos to the free list.  */
+ 
+ static void
+ undo_commit ()
+ {
+   struct undo *undo, *next;
+ 
+   for (undo = undobuf.undos; undo; undo = next)
+     {
+       next = undo->next;
+       undo->next = undobuf.frees;
+       undobuf.frees = undo;
+     }
+   undobuf.undos = undobuf.previous_undos = 0;
+ }
+ 
  
  /* Find the innermost point within the rtx at LOC, possibly LOC itself,
     where we have an arithmetic expression and return that point.  LOC will
Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.181
diff -c -p -d -r1.181 flow.c
*** flow.c	1999/11/01 23:19:43	1.181
--- flow.c	1999/11/05 00:42:31
*************** life_analysis (f, nregs, file, remove_de
*** 2466,2473 ****
    if (file)
      dump_flow_info (file);
  
!   BITMAP_FREE (uid_volatile);
!   free (uid_volatile);
    free_basic_block_vars (1);
  }
  
--- 2466,2472 ----
    if (file)
      dump_flow_info (file);
  
!   BITMAP_XFREE (uid_volatile);
    free_basic_block_vars (1);
  }
  
*************** life_analysis_1 (f, nregs, flags)
*** 2940,2945 ****
--- 2939,2945 ----
      blocks = sbitmap_alloc (n_basic_blocks);
      sbitmap_ones (blocks);
      calculate_global_regs_live (blocks, blocks, flags & PROP_SCAN_DEAD_CODE);
+     sbitmap_free (blocks);
    }
  
    /* The only pseudos that are live at the beginning of the function are
Index: local-alloc.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/local-alloc.c,v
retrieving revision 1.52
diff -c -p -d -r1.52 local-alloc.c
*** local-alloc.c	1999/11/04 20:51:04	1.52
--- local-alloc.c	1999/11/05 00:42:32
*************** local_alloc ()
*** 420,425 ****
--- 420,426 ----
    free (qty_phys_copy_sugg);
    free (qty_phys_num_copy_sugg);
    free (qty_phys_sugg);
+   free (qty_phys_num_sugg);
    free (qty_birth);
    free (qty_death);
    free (qty_first_reg);
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/stmt.c,v
retrieving revision 1.107
diff -c -p -d -r1.107 stmt.c
*** stmt.c	1999/11/05 00:35:10	1.107
--- stmt.c	1999/11/05 00:42:33
*************** typedef struct case_node *case_node_ptr;
*** 106,111 ****
--- 106,112 ----
  /* These are used by estimate_case_costs and balance_case_nodes.  */
  
  /* This must be a signed type, and non-ANSI compilers lack signed char.  */
+ static short cost_table_[129];
  static short *cost_table;
  static int use_cost_table;
  
*************** estimate_case_costs (node)
*** 5694,5700 ****
  
    if (cost_table == NULL)
      {
!       cost_table = ((short *) xcalloc (129, sizeof (short))) + 1;
  
        for (i = 0; i < 128; i++)
  	{
--- 5695,5701 ----
  
    if (cost_table == NULL)
      {
!       cost_table = cost_table_ + 1;
  
        for (i = 0; i < 128; i++)
  	{
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.254
diff -c -p -d -r1.254 toplev.c
*** toplev.c	1999/11/04 07:23:58	1.254
--- toplev.c	1999/11/05 00:42:33
*************** compile_file (name)
*** 3053,3065 ****
  	asm_out_file = stdout;
        else
  	{
- 	  int len = strlen (dump_base_name);
- 	  register char *dumpname = (char *) xmalloc (len + 6);
- 	  strcpy (dumpname, dump_base_name);
- 	  strip_off_ending (dumpname, len);
- 	  strcat (dumpname, ".s");
  	  if (asm_file_name == 0)
! 	    asm_file_name = xstrdup (dumpname);
  	  if (!strcmp (asm_file_name, "-"))
  	    asm_out_file = stdout;
  	  else
--- 3053,3067 ----
  	asm_out_file = stdout;
        else
  	{
  	  if (asm_file_name == 0)
! 	    {
! 	      int len = strlen (dump_base_name);
! 	      char *dumpname = (char *) xmalloc (len + 6);
! 	      memcpy (dumpname, dump_base_name, len + 1);
! 	      strip_off_ending (dumpname, len);
! 	      strcat (dumpname, ".s");
! 	      asm_file_name = dumpname;
! 	    }
  	  if (!strcmp (asm_file_name, "-"))
  	    asm_out_file = stdout;
  	  else


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