http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57884
Bug ID: 57884 Summary: False positive in libgfortran finalization Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: eugene.zelenko at gmail dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org Created attachment 30497 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30497&action=edit Main file which calls FORTRAN procedure Hi! My application contains some part of FORTRAN code. When I tried to compile it with address sanitizer and then run executable, I got error at the end: ==14628== ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x56732c8c #0 0x5556c854 (/gcc481/lib/libasan.so.0.0.0+0x16854) #1 0x56bf7a20 (/gcc481/lib/libgfortran.so.3.0.0+0xc2a20) ==14628== ABORTING Problematic code is freeing of FORTRAN wrapper for stdin in raw_close(). Strangely, but same operations for stdout and stderr wrappers were performed without problem. All three wrappers are created with same fd_to_stream() function. This problem is observed with GCC 4.8.0 and 4.8.1 built on Red Hat Enterprise Linux 5.5 with 32 and 64 bit executables. But same versions of GCC build on Red Hat Enterprise Linux 6.0 are fine. Example build script: !/bin/csh set echo on set Mode = "-m32" set GCCHome = "/gcc481" $GCCHome/bin/gfortran -std=legacy -g $Mode -fsanitize=address -c zcopy.f -o zcopy.o $GCCHome/bin/gcc -g $Mode -fsanitize=address -c main.c -o main.o $GCCHome/bin/gcc $Mode main.o zcopy.o -lasan -lgfortran -o main.exe GDB backtrace for: #7 0x56bf7a21 in raw_close (s=0x56732c8c <__interceptor_calloc::calloc_memory_for_dlsym+428>) at /gcc481_src/gcc-4.8.1/libgfortran/io/unix.c:416 #8 0x56bf7462 in sclose (s=<optimized out>) at /gcc481_src/gcc-4.8.1/libgfortran/io/unix.h:94 #9 close_unit_1 (u=0x56732ae0 <__interceptor_calloc::calloc_memory_for_dlsym>, locked=locked@entry=1) at /gcc481_src/gcc-4.8.1/libgfortran/io/unit.c:653 #10 0x56bf75da in _gfortrani_close_units () at /gcc481_src/gcc-4.8.1/libgfortran/io/unit.c:716 #11 0x56b48514 in cleanup () at /gcc481_src/gcc-4.8.1/libgfortran/runtime/main.c:250 #12 0x56b45808 in __do_global_dtors_aux () from /home/tammy/gcc481/lib/libgfortran.so.3 #13 0x56c10830 in _fini () from /home/tammy/gcc481/lib/libgfortran.so.3 #14 0x0082580e in _dl_fini () from /lib/ld-linux.so.2 #15 0x00865da9 in exit () from /lib/libc.so.6 #16 0x0084fea4 in __libc_start_main () from /lib/libc.so.6 #17 0x08048561 in _start () Eugene.