Allocatable component not deallocated after ERROR STOP
0 reputation · 03 Sept 2020, 05:30 UTC
The goal is to confirm whether allocatable components of a derived type are automatically deallocated when the program terminates with an ERROR STOP statement.
The Fortran standard specifies that allocatable components are deallocated when the parent object is deallocated or goes out of scope, but it does not guarantee this behavior during abnormal termination via ERROR STOP, especially if the component has the TARGET attribute and is associated with a pointer.
Compiler implementations may differ in how they handle stack unwinding and resource cleanup after an error stop, leading to uncertainty about whether a memory leak occurs in practice.
Does the standard require deallocation of allocatable components on ERROR STOP? Does the presence of a TARGET attribute and pointer association affect this requirement? How do major Fortran compilers (e.g., gfortran, ifort, flang) behave regarding leak detection for this scenario?