https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88399
Bug ID: 88399
Summary: program segmentation faults when out-of-memory
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: schorkl72 at gmail dot com
Target Milestone: ---
Created attachment 45176
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45176&action=edit
wrapper for malloc() to simulate out-of-memory
The following program segmentation faults if allocate is unsuccessful:
program main
type initialized
integer :: i = 42
end type
type(initialized), pointer :: ptr
integer :: st
allocate(ptr, stat=st)
if (st /= 0) stop "allocation failed"
end
To test it, compile the code snippet (say main.f90) and the attached malloc
wrapper as:
$ gfortran -c main.f90
$ gcc -c wrap_malloc.c
$ gfortran -Wl,--wrap=malloc main.o wrap_malloc.o
$ ./a.out
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x7EFEF00CBE08
#1 0x7EFEF00CAF90
#2 0x7EFEEFD1B4AF
#3 0x40073A in MAIN__ at main.f90:?
Segmentation fault
The problem is the default initialization (= 42) of the derived type component.
Without it, the program runs correctly and stops with "allocation failed".