aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2020-09-17 14:01:09 +0200
committerTobias Burnus <tobias@codesourcery.com>2020-09-17 14:01:09 +0200
commitc12facd22881517127ebbe213d7ecc7fc1fcea4e (patch)
treed8c15903cdb63512718f5ca1a473c7afcf2ec993 /gcc
parentc7f4be78cb61006492d16375aba5392f580cd633 (diff)
downloadgcc-c12facd22881517127ebbe213d7ecc7fc1fcea4e.zip
gcc-c12facd22881517127ebbe213d7ecc7fc1fcea4e.tar.gz
gcc-c12facd22881517127ebbe213d7ecc7fc1fcea4e.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/decl.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index c612b492..326e6f5 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -9819,6 +9819,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;
}