public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Fortran: Avoid double-free with parse error (PR96041, PR93423)
@ 2020-09-28  9:14 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-28  9:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:66b9a560a6322081e041827cf73080f519c7198c

commit 66b9a560a6322081e041827cf73080f519c7198c
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 3d04e65015d..6249562de29 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -9460,6 +9460,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;
     }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-28  9:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-28  9:14 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Fortran: Avoid double-free with parse error (PR96041, PR93423) Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).