https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65563
Bug ID: 65563 Summary: Segfault on reopening fort.xxx file with explicit name Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: tkoenig at gcc dot gnu.org This is inspired by https://stackoverflow.com/questions/29238857/fortran-error-about-eof-marker/ ,but is slightly different. This segfaults: variable_1 = 0 open(345,iostat=ios, form='unformatted') read(345, err=37, end=37) variable_1 close(345) go to 38 37 continue 38 continue open(522, file="fort.345", form='unformatted') write(522) variable_1 rewind(522) close(522) end program Backtrace: #0 0x00007ffff778d42a in strlen () from /lib64/libc.so.6 #1 0x00007ffff778d14e in strdup () from /lib64/libc.so.6 #2 0x00007ffff7ba1eec in _gfortrani_filename_from_unit (n=<optimized out>) at ../../../trunk/libgfortran/io/unit.c:833 #3 0x00007ffff7ad83af in _gfortrani_show_locus (cmp=0x7fffffffd7f0) at ../../../trunk/libgfortran/runtime/error.c:266 #4 0x00007ffff7ad8990 in _gfortrani_generate_error (cmp=cmp@entry=0x7fffffffd7f0, family=family@entry=5004, message=0x7ffff7bb8b60 "File already opened in another unit", message@entry=0x0) at ../../../trunk/libgfortran/runtime/error.c:561 #5 0x00007ffff7b9a1f4 in _gfortrani_new_unit (opp=opp@entry=0x7fffffffd7f0, u=u@entry=0x6083e0, flags=flags@entry=0x7fffffffd790) at ../../../trunk/libgfortran/io/open.c:493 #6 0x00007ffff7b9a6ee in already_open (flags=<optimized out>, u=<optimized out>, opp=<optimized out>) at ../../../trunk/libgfortran/io/open.c:694