Patchwork [fortran,committed] Don't initialize mpfr data twice.

login
register
mail settings
Submitter Mikael Morin
Date July 12, 2010, 2:37 p.m.
Message ID <4C3B28A9.9050905@sfr.fr>
Download mbox | patch
Permalink /patch/58616/
State New
Headers show

Comments

Mikael Morin - July 12, 2010, 2:37 p.m.
Hello,

gfc_get_constant_expr initializes the mpfr data, so there is no need to 
do so afterwards. This fixes for example some of the memory leaks 
present in the following testcase:

subroutine a
   integer :: i
   real    :: r
   complex :: c
   i = 0
   r = 0.0
   c = (0.0, 0.0)
end subroutine a

==33603== 16 bytes in 1 blocks are definitely lost in loss record 23 of 296
==33603==    at 0x25A67B: malloc (in 
/usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so)
==33603==    by 0x20F03B8: __gmp_default_allocate (in 
/usr/local/lib/libgmp.so.10)
==33603==    by 0x1FBF6C5: mpfr_init2 (in /usr/local/lib/libmpfr.so.4)
==33603==    by 0x4BB05D: gfc_get_constant_expr (expr.c:165)
==33603==    by 0x51FD29: build_default_init_expr (resolve.c:9132)
==33603==    by 0x5200E6: apply_default_init_local (resolve.c:9267)
==33603==    by 0x5208C4: resolve_fl_variable (resolve.c:9480)
==33603==    by 0x526554: resolve_symbol (resolve.c:11798)
==33603==    by 0x54068C: traverse_ns (symbol.c:3332)
==33603==    by 0x5406BB: traverse_ns (symbol.c:3335)
==33603==    by 0x5406BB: traverse_ns (symbol.c:3335)
==33603==    by 0x5406FA: gfc_traverse_ns (symbol.c:3348)


Committed as obvious at revision 162081

Mikael

Patch

Index: ChangeLog
===================================================================
--- ChangeLog	(révision 162080)
+++ ChangeLog	(révision 162081)
@@ -1,3 +1,8 @@ 
+2010-07-12  Mikael Morin  <mikael@gcc.gnu.org>
+
+	* expr.c (gfc_get_int_expr): Don't initialize mpfr data twice.
+	* resolve.c (build_default_init_expr): Ditto.
+
 2010-07-11  Tobias Burnus  <burnus@net-b.de>
 
 	PR fortran/44702
Index: expr.c
===================================================================
--- expr.c	(révision 162080)
+++ expr.c	(révision 162081)
@@ -215,7 +215,7 @@  gfc_get_int_expr (int kind, locus *where, int valu
   p = gfc_get_constant_expr (BT_INTEGER, kind,
 			     where ? where : &gfc_current_locus);
 
-  mpz_init_set_si (p->value.integer, value);
+  mpz_set_si (p->value.integer, value);
 
   return p;
 }
Index: resolve.c
===================================================================
--- resolve.c	(révision 162080)
+++ resolve.c	(révision 162081)
@@ -9139,7 +9139,7 @@  build_default_init_expr (gfc_symbol *sym)
     {    
     case BT_INTEGER:
       if (gfc_option.flag_init_integer != GFC_INIT_INTEGER_OFF)
-	mpz_init_set_si (init_expr->value.integer, 
+	mpz_set_si (init_expr->value.integer, 
 			 gfc_option.flag_init_integer_value);
       else
 	{
@@ -9149,7 +9149,6 @@  build_default_init_expr (gfc_symbol *sym)
       break;
 
     case BT_REAL:
-      mpfr_init (init_expr->value.real);
       switch (gfc_option.flag_init_real)
 	{
 	case GFC_INIT_REAL_SNAN:
@@ -9179,7 +9178,6 @@  build_default_init_expr (gfc_symbol *sym)
       break;
 	  
     case BT_COMPLEX:
-      mpc_init2 (init_expr->value.complex, mpfr_get_default_prec());
       switch (gfc_option.flag_init_real)
 	{
 	case GFC_INIT_REAL_SNAN: