https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99529
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> --- Regarding calling newunit_alloc, that's due to libgfortran/io/unit.c's: get_unit (st_parameter_dt *dtp, int do_create) { gfc_unit *unit; if ((dtp->common.flags & IOPARM_DT_HAS_INTERNAL_UNIT) != 0) { int kind; if (dtp->common.unit == GFC_INTERNAL_UNIT) kind = 1; else if (dtp->common.unit == GFC_INTERNAL_UNIT4) kind = 4; else internal_error (&dtp->common, "get_unit(): Bad internal unit KIND"); dtp->u.p.unit_is_internal = 1; dtp->common.unit = newunit_alloc (); unit = get_gfc_unit (dtp->common.unit, do_create); set_internal_unit (dtp, unit, kind); fbuf_init (unit, 128); return unit; } * * * >From reading the report & looking at the code superficially, it seems as if a patch is needed like: diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 27bee9d4e01..a6f115d5803 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -4360,3 +4360,5 @@ st_read_done_worker (st_parameter_dt *dtp) } + LOCK (&unit_lock); newunit_free (dtp->common.unit); + UNLOCK (&unit_lock); } @@ -4448,3 +4450,5 @@ st_write_done_worker (st_parameter_dt *dtp) } + LOCK (&unit_lock); newunit_free (dtp->common.unit); + UNLOCK (&unit_lock); }