https://gcc.gnu.org/g:4b2e3dff5615a16532f42459fc5d0400c6d61f05

commit 4b2e3dff5615a16532f42459fc5d0400c6d61f05
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Fri May 10 11:17:41 2024 +0200

    fortran: Fix leaked symbol
    
    For a symbol we create, this adds a reference to a it in a namespace, so
    that its memory is not leaked.  A hidden name is used to avoid polluting
    the namespace.
    
    gcc/fortran/ChangeLog:
    
            * decl.cc (get_proc_name): Reference the interface symbol in the
            namespace under a hidden name.

Diff:
---
 gcc/fortran/decl.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index b8308aeee550..ce0fb6bae594 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -1335,6 +1335,10 @@ get_proc_name (const char *name, gfc_symbol **result, 
bool module_fcn_entry)
       /* Create a partially populated interface symbol to carry the
         characteristics of the procedure and the result.  */
       sym->tlink = gfc_new_symbol (name, sym->ns);
+      gfc_symtree *s = gfc_get_unique_symtree (sym->ns);
+      s->n.sym = sym->tlink;
+      s->n.sym->refs++;
+
       gfc_add_type (sym->tlink, &(sym->ts), &gfc_current_locus);
       gfc_copy_attr (&sym->tlink->attr, &sym->attr, NULL);
       if (sym->attr.dimension)

Reply via email to