https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911
--- Comment #4 from anlauf at gcc dot gnu.org ---
Running f951 on the testcase under valgrind shows (among others) a
frontend memleak in gfc_resolve_substring_charlen, obviously fixed by
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 44f89f6afb4..b1f36efb10b 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -5392,11 +5392,7 @@ gfc_resolve_substring_charlen (gfc_expr *e)
end = NULL;
if (!start || !end)
- {
- gfc_free_expr (start);
- gfc_free_expr (end);
- return;
- }
+ goto cleanup;
/* Length = (end - start + 1).
Check first whether it has a constant length. */
@@ -5431,6 +5427,10 @@ gfc_resolve_substring_charlen (gfc_expr *e)
/* Make sure that the length is simplified. */
gfc_simplify_expr (e->ts.u.cl->length, 1);
gfc_resolve_expr (e->ts.u.cl->length);
+
+cleanup:
+ gfc_free_expr (start);
+ gfc_free_expr (end);
}