This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [patch, libfortran] PR40508 Memory Leak
- From: dominiq at lps dot ens dot fr (Dominique Dhumieres)
- To: fortran at gcc dot gnu dot org
- Cc: jvdelisle at verizon dot net
- Date: Sun, 21 Jun 2009 23:32:52 +0200
- Subject: Re: [patch, libfortran] PR40508 Memory Leak
Jerry,
AFAICT your patch in http://gcc.gnu.org/ml/fortran/2009-06/msg00233.html
fixes the memory leak.
The diff between my 4.4.1 (noleak) and patched trunk is:
--- libgfortran/io/format.c 2009-05-27 13:54:19.000000000 +0200
+++ /opt/gcc/gcc-4.5-work/libgfortran/io/format.c 2009-06-21 22:20:16.000000000 +0200
@@ -87,7 +87,12 @@ free_format_hash_table (gfc_unit *u)
for (i = 0; i < FORMAT_HASH_SIZE; i++)
{
if (u->format_hash_table[i].hashed_fmt != NULL)
- free_format_data (u->format_hash_table[i].hashed_fmt);
+ {
+ free_format_data (u->format_hash_table[i].hashed_fmt);
+ free_mem (u->format_hash_table[i].key);
+ }
+ u->format_hash_table[i].key = NULL;
+ u->format_hash_table[i].key_len = 0;
u->format_hash_table[i].hashed_fmt = NULL;
}
}
@@ -164,7 +169,11 @@ save_parsed_format (st_parameter_dt *dtp
free_format_data (u->format_hash_table[hash].hashed_fmt);
u->format_hash_table[hash].hashed_fmt = NULL;
- u->format_hash_table[hash].key = dtp->format;
+ if (u->format_hash_table[hash].key != NULL)
+ free_mem (u->format_hash_table[hash].key);
+ u->format_hash_table[hash].key = get_mem (dtp->format_len);
+ memcpy (u->format_hash_table[hash].key, dtp->format, dtp->format_len);
+
u->format_hash_table[hash].key_len = dtp->format_len;
u->format_hash_table[hash].hashed_fmt = dtp->u.p.fmt;
}
@@ -1209,7 +1218,8 @@ parse_format (st_parameter_dt *dtp)
free_format_hash_table (dtp->u.p.current_unit);
return;
}
- save_parsed_format (dtp);
+ if (!is_internal_unit (dtp))
+ save_parsed_format (dtp);
}
It would be interesting to understand why there is no leak with the - variant.
Thanks for the patch.
Dominique