[gcc r9-8921] Fortran: Avoid double-free with parse error (PR96041, PR93423)

Harald Anlauf anlauf@gcc.gnu.org
Sat Sep 19 18:32:11 GMT 2020


https://gcc.gnu.org/g:0e442063a0adf01e6348e9fc55cc3e9869974769

commit r9-8921-g0e442063a0adf01e6348e9fc55cc3e9869974769
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Thu Sep 17 14:01:09 2020 +0200

    Fortran: Avoid double-free with parse error (PR96041, PR93423)
    
    gcc/fortran/
    
            PR fortran/96041
            PR fortran/93423
            * decl.c (gfc_match_submod_proc): Avoid later double-free
            in the error case.
    
    (cherry picked from commit c12facd22881517127ebbe213d7ecc7fc1fcea4e)

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

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 95813d7f69d..b7987fb24ba 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -9693,6 +9693,15 @@ gfc_match_submod_proc (void)
 
   if (gfc_match_eos () != MATCH_YES)
     {
+      /* Unset st->n.sym. Note: in reject_statement (), the symbol changes are
+	 undone, such that the st->n.sym->formal points to the original symbol;
+	 if now this namespace is finalized, the formal namespace is freed,
+	 but it might be still needed in the parent namespace.  */
+      gfc_symtree *st = gfc_find_symtree (gfc_current_ns->sym_root, sym->name);
+      st->n.sym = NULL;
+      gfc_free_symbol (sym->tlink);
+      sym->tlink = NULL;
+      sym->refs--;
       gfc_syntax_error (ST_MODULE_PROC);
       return MATCH_ERROR;
     }


More information about the Gcc-cvs mailing list