https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119502
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <jvdeli...@gcc.gnu.org>: https://gcc.gnu.org/g:ee6173800ed1f9b653a85019ad2fa8e6d883823a commit r15-9415-gee6173800ed1f9b653a85019ad2fa8e6d883823a Author: Jerry DeLisle <jvdeli...@gcc.gnu.org> Date: Sat Apr 12 19:51:23 2025 -0700 Fortran: Fix runtime segfault closing negative unit When closing a UNIT with an invalid negative unit number, a segfault ensued. This patch adds checks for these conditions and issues errors. PR libfortran/119502 libgfortran/ChangeLog: * io/close.c (st_close): Issue an error and avoid calling close_share when there is no stream assigned. * io/open.c (st_open): If there is no stream assigned to the unit, unlock the unit and issue an error. gcc/testsuite/ChangeLog: * gfortran.dg/pr119502.f90: New test.