[PATCH,FORTRAN] Fix memory leak in finalization wrappers

Mikael Morin morin-mikael@orange.fr
Fri Nov 5 18:46:16 GMT 2021


Le 29/10/2021 à 01:58, Bernhard Reutner-Fischer via Fortran a écrit :
> On Wed, 27 Oct 2021 23:39:43 +0200
> Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
> 
>> Ping
>> [hmz. it's been a while, I'll rebase and retest this one.
>> Ok if it passes?]
> Testing passed without any new regressions.
> Ok for trunk?
> thanks,
>>
>> On Mon, 15 Oct 2018 10:23:06 +0200
>> Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
>>
>>> If a finalization is not required we created a namespace containing
>>> formal arguments for an internal interface definition but never used
>>> any of these. So the whole sub_ns namespace was not wired up to the
>>> program and consequently was never freed. The fix is to simply not
>>> generate any finalization wrappers if we know that it will be unused.
>>> Note that this reverts back to the original r190869
>>> (8a96d64282ac534cb597f446f02ac5d0b13249cc) handling for this case
>>> by reverting this specific part of r194075
>>> (f1ee56b4be7cc3892e6ccc75d73033c129098e87) for PR fortran/37336.
>>>
I’m a bit concerned by the loss of the null_expr’s type interface.
I can’t convince myself that it’s either absolutely necessary or 
completely useless.
Tobias didn’t include a test in his commit unfortunately, but I bet he 
did the change on purpose.
Don’t you get the same effect on the memory leaks if you keep just the 
following hunk?

 >>> @@ -1605,8 +1608,7 @@ generate_finalization_wrapper (gfc_symbol 
*derived, gfc_namespace *ns,
 >>>     /* Set up the namespace.  */
 >>>     sub_ns = gfc_get_namespace (ns, 0);
 >>>     sub_ns->sibling = ns->contained;
 >>> -  if (!expr_null_wrapper)
 >>> -    ns->contained = sub_ns;
 >>> +  ns->contained = sub_ns;
 >>>     sub_ns->resolved = 1;
 >>>
 >>>     /* Set up the procedure symbol.  */


The rest of the changes (appart from class.c) are mostly OK with the nit 
below and should be put in their own commit.

 >>> @@ -3826,10 +3828,8 @@ free_tb_tree (gfc_symtree *t)
 >>>
 >>>     free_tb_tree (t->left);
 >>>     free_tb_tree (t->right);
 >>> -
 >>> -  /* TODO: Free type-bound procedure structs themselves; probably 
needs some
 >>> -     sort of ref-counting mechanism.  */
 >>>     free (t->n.tb);

Please keep a comment; it remains somehow valid but could be updated 
maybe: gfc_typebound_proc’s u.generic field for example is nowhere freed 
as far as I know.

Thanks.

Mikael


More information about the Gcc-patches mailing list