[Mono-devel-list] Possible leaks when freeing CFG after Jitting

Derek Woo derek at eecg.toronto.edu
Sat Apr 24 01:52:37 EDT 2004


Hello,

The following fields under MonoBasicBlock is not free-d together with the 
CFG in mono_destroy_compile() after the Jitting. A potential memory leak 
whenever loop info is compiled.

GList *loop_blocks
GList *dominated

I hope I am not missing anything. This is the first time I submit patch so 
any comment is greatly appreciated.


Changes:

* dominators.c : added 3 functions to free up GLists allocated during 
dominance/loop info is compiled

* mono_destroy_compile() (mini.c) : insert the free-up calls

* mini.h : added the function prototype mono_free_loop_info()


Thanks,

--Derek
-------------- next part --------------
Index: mono/mini/dominators.c
===================================================================
RCS file: /mono/mono/mono/mini/dominators.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 dominators.c
*** mono/mini/dominators.c	5 Apr 2003 19:21:32 -0000	1.1
--- mono/mini/dominators.c	24 Apr 2004 06:33:33 -0000
*************** mono_compute_natural_loops (MonoCompile 
*** 477,479 ****
--- 477,519 ----
  
  }
  
+ static void
+ clear_idominators(MonoCompile *cfg)
+ {
+ 	guint i;
+     
+ 	for ( i=0 ; i < cfg->num_bblocks ; ++i) {
+ 		if (cfg->bblocks[i]->dominated) {
+ 			g_list_free(cfg->bblocks[i]->dominated);        
+ 			cfg->bblocks[i]->dominated = NULL;
+ 		}
+ 	}
+ 
+ 	cfg->comp_done &= ~MONO_COMP_IDOM;   
+ }
+ 
+ static void
+ clear_loops(MonoCompile *cfg)
+ {
+ 	guint i;
+     
+ 	for ( i=0 ; i < cfg->num_bblocks ; ++i) {
+ 		cfg->bblocks[i]->nesting = 0;
+ 		if (cfg->bblocks[i]->loop_blocks) {
+ 			g_list_free(cfg->bblocks[i]->loop_blocks);        
+ 			cfg->bblocks[i]->loop_blocks = NULL;
+ 		}
+ 	}
+ 
+ 	cfg->comp_done &= ~MONO_COMP_LOOPS;   
+ }
+ 
+ void
+ mono_free_loop_info(MonoCompile *cfg)
+ {
+     if (cfg->comp_done & MONO_COMP_IDOM)
+         clear_idominators (cfg);
+     if (cfg->comp_done & MONO_COMP_LOOPS)
+         clear_loops (cfg);
+ }
+     
Index: mono/mini/mini.c
===================================================================
RCS file: /mono/mono/mono/mini/mini.c,v
retrieving revision 1.222
diff -c -3 -p -r1.222 mini.c
*** mono/mini/mini.c	22 Apr 2004 16:45:12 -0000	1.222
--- mono/mini/mini.c	24 Apr 2004 06:33:33 -0000
*************** mono_destroy_compile (MonoCompile *cfg)
*** 6491,6496 ****
--- 6491,6497 ----
  {
  	//mono_mempool_stats (cfg->mempool);
  	g_hash_table_destroy (cfg->bb_hash);
+   mono_free_loop_info(cfg);
  	if (cfg->rs)
  		mono_regstate_free (cfg->rs);
  	if (cfg->spvars)
Index: mono/mini/mini.h
===================================================================
RCS file: /mono/mono/mono/mini/mini.h,v
retrieving revision 1.61
diff -c -3 -p -r1.61 mini.h
*** mono/mini/mini.h	21 Apr 2004 13:44:28 -0000	1.61
--- mono/mini/mini.h	24 Apr 2004 06:33:33 -0000
*************** void        mono_ssa_remove             
*** 761,766 ****
--- 761,767 ----
  void        mono_ssa_cprop                      (MonoCompile *cfg);
  void        mono_ssa_deadce                     (MonoCompile *cfg);
  void        mono_ssa_strength_reduction         (MonoCompile *cfg);
+ void        mono_free_loop_info                 (MonoCompile *cfg);
  
  /* debugging support */
  void      mono_debug_init_method                (MonoCompile *cfg, MonoBasicBlock *start_block,


More information about the Mono-devel-list mailing list