[patch, libgfortran] Memory issues related to PR78549

Jerry DeLisle jvdelisle@charter.net
Mon Dec 11 03:55:00 GMT 2017


Hi all,

While doing addition testing for the subject mentioned PR I discovered numerous
un-freed memory allocations. I reported the problem in comment 30 of the PR.

The attached patch cleans this up by opening the internal unit structures during
program initialization and allowing the automatic closure similar to
pre-connected units. The internal stream structures are created and freed at the
beginning and end of each I/O operation.  I fix a few loose ends.

Regression tested on x86_64.

OK for trunk?  Also needed for same issue in 7.

Regards,

Jerry

2017-12-11  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/78549
	* io/inquire.c (inquire_via_unit): Adjust test for existence for
	pre-connected internal units.
	* io/transfer.c (finalize_transfer): When done with a transfer
	to internal units, free the format buffer and close the stream.
	(st_read_done): Delete freeing the stream, now handled using
	sclose in finalize_transfer. (st_write_done): Likewise.
	* io/unit.c (get_unit): Return NULL for special reserved unit
	numbers, signifying not accessible to the user.
	(init_units): Insert the two special internal units into the
	unit treap. This makes these unit structures available without
	further allocations for later use by internal unit I/O. These
	units are automatically deleted by normal program termination.
	* unix.c (mem_close): Add a guard check to protect from double free.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: submit.diff
Type: text/x-patch
Size: 3151 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20171211/cc2cd568/attachment.bin>


More information about the Fortran mailing list