This is the mail archive of the 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]
Other format: [Raw text]

[patch, libfortran] PR40508 Memory Leak

Hi all,

First to explain the problem. Internal units have a gfc_unit structure that is allocated in memory at the beginning of an IO statement (read/write) and freed at the end. This means that there is no unit structure retained from one statement to the next and therefore saving format data pointed to in that structure is moot.

The problem begins with bothering to save the format to begin with and ends with not freeing it within free_internal_unit. This means that the following patch is actually the best way to go for now.

This hints at a further optimization we could do. Why allocate an internal unit structure every time we do an I/O? There may be a way to reuse an internal unit structure for repeated units. I will save that for a later date.

I also have a confession to make. In format.c you will see where I added a bool save_format flag. This was the start of disabling saving formats for specific cases that could be troublesome, internal units being one of those. I failed to finish that part of the patch when I submitted it before. Regardless, I am working on these related items as part of the CP2K bug we found. When I get that all tested, I will submit a full patch.

In the meantime, OK to commit the following to trunk in the interim?

Regression tested on x86-64-linux-gnu.



2009-06-21 Jerry DeLisle <>

	PR libfortran/40508
	* io/format.c: Don't save parsed format data for internal units.

Index: format.c
--- format.c	(revision 148448)
+++ format.c	(working copy)
@@ -1218,7 +1218,8 @@ parse_format (st_parameter_dt *dtp)
       free_format_hash_table (dtp->u.p.current_unit);
-  save_parsed_format (dtp);
+  if (!is_internal_unit (dtp))
+    save_parsed_format (dtp);

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