[Patch, Fortran] PR 40877: memory leaks with gfc_charlen

Janus Weil janus@gcc.gnu.org
Thu Aug 6 11:11:00 GMT 2009


Hi all,

this patch fixes a number of memory leaks with gfc_charlen. All
gfc_charlen structures are normally put into a linked list in their
respective namespace (ns->cl_list). When the namespace is cleaned up
in the end, this list of gfc_charlen's is also freed. Any gfc_charlen
which is not inside such a list will be a memory leak, since it is
never deallocated.

When working on PR 40822 (where I introduced a function
'gfc_new_charlen' which makes sure the charlen is correctly put into a
ns->cl_list), I noticed a couple of places where a gfc_charlen is not
put into such a list. I checked these, and concluded that indeed all
of them seem to be memory leaks. This patch plugs these leaks and adds
a new argument to 'gfc_new_charlen', so that this function can also be
used to create a new gfc_charlen as a copy of an existing one.

Regtested on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus


2009-08-06  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40877
	* array.c (gfc_resolve_character_array_constructor): Add NULL argument
	to gfc_new_charlen.
	* decl.c (add_init_expr_to_sym,variable_decl,match_char_spec,
	gfc_match_implicit): Ditto.
	* expr.c (simplify_const_ref): Fix memory leak.
	(gfc_simplify_expr): Add NULL argument to gfc_new_charlen.
	* gfortran.h (gfc_new_charlen): Modified prototype.
	* iresolve.c (check_charlen_present,gfc_resolve_char_achar): Add NULL
	argument to gfc_new_charlen.
	* module.c (mio_charlen): Ditto.
	* resolve.c (gfc_resolve_substring_charlen,
	gfc_resolve_character_operator,fixup_charlen): Ditto.
	(resolve_fl_derived,resolve_symbol): Add argument to gfc_charlen.
	* symbol.c (gfc_new_charlen): Add argument 'old_cl' (to make a copy of
	an existing charlen).
	(gfc_set_default_type,generate_isocbinding_symbol): Fix memory leak.
	(gfc_copy_formal_args_intr): Add NULL argument to gfc_new_charlen.
	* trans-decl.c (create_function_arglist): Fix memory leak.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr40877.diff
Type: text/x-diff
Size: 10327 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090806/f90a8e9a/attachment.bin>


More information about the Fortran mailing list