aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2024-11-26 20:37:35 +0100
committerHarald Anlauf <anlauf@gmx.de>2024-11-26 23:09:40 +0100
commit94f98f67f7271f6f962d1c562559aa8a4839f505 (patch)
treefddd7fbe03a8b661d1d8b5e2495b2be9054e1e4a /gcc
parent4a2352828ec4fdfb70dda5405b5a907b46248eec (diff)
downloadgcc-94f98f67f7271f6f962d1c562559aa8a4839f505.zip
gcc-94f98f67f7271f6f962d1c562559aa8a4839f505.tar.gz
gcc-94f98f67f7271f6f962d1c562559aa8a4839f505.tar.bz2
Fortran: fix minor front-end memleaks
gcc/fortran/ChangeLog: * expr.cc (find_inquiry_ref): Fix memleak introduced by scanning the reference chain to find and simplify inquiry references. * symbol.cc (gfc_copy_formal_args_intr): Free formal namespace when not needed to avoid a front-end memleak.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/expr.cc6
-rw-r--r--gcc/fortran/symbol.cc2
2 files changed, 7 insertions, 1 deletions
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 6b40e8e..a997bda 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1833,6 +1833,7 @@ find_inquiry_ref (gfc_expr *p, gfc_expr **newp)
{
gfc_ref *ref;
gfc_ref *inquiry = NULL;
+ gfc_ref *inquiry_head;
gfc_expr *tmp;
tmp = gfc_copy_expr (p);
@@ -1858,6 +1859,7 @@ find_inquiry_ref (gfc_expr *p, gfc_expr **newp)
return false;
}
+ inquiry_head = inquiry;
gfc_resolve_expr (tmp);
/* Leave these to the backend since the type and kind is not confirmed until
@@ -1930,7 +1932,7 @@ find_inquiry_ref (gfc_expr *p, gfc_expr **newp)
mpc_imagref (tmp->value.complex), GFC_RND_MODE);
break;
}
- // TODO: Fix leaking expr tmp, when simplify is done twice.
+
if (inquiry->next)
gfc_replace_expr (tmp, *newp);
}
@@ -1944,10 +1946,12 @@ find_inquiry_ref (gfc_expr *p, gfc_expr **newp)
}
gfc_free_expr (tmp);
+ gfc_free_ref_list (inquiry_head);
return true;
cleanup:
gfc_free_expr (tmp);
+ gfc_free_ref_list (inquiry_head);
return false;
}
diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index e803cdd..f13cb18 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -4910,6 +4910,8 @@ gfc_copy_formal_args_intr (gfc_symbol *dest, gfc_intrinsic_sym *src,
if (dest->formal != NULL)
/* The current ns should be that for the dest proc. */
dest->formal_ns = gfc_current_ns;
+ else
+ gfc_free_namespace (gfc_current_ns);
/* Restore the current namespace to what it was on entry. */
gfc_current_ns = parent_ns;
}