An associate construct causes the alloc error "pointer being freed was
not allocated" when the selector is a structure constructor for a
derived type with an allocatable component and a procedure pointer
component.  This same error occurs if a function returning the same
type replaces the structure constructor. The same error occurs for
programs compiled with gfortran 12.4.0, 13.3.0, 14.2.0, and 15.0.1:

% cat all.f90
  implicit none

  type foo_t
    integer, allocatable :: i_
    procedure(f), pointer, nopass :: f_
  end type

  associate(foo => foo_t(1,f))
  end associate

contains

  function f()
    logical, allocatable :: f
    f = .true.
  end function

end

% gfortran all.f90
% ./a.out
a.out(99502,0x1ed7e4840) malloc: *** error for object 0x200000000:
pointer being freed was not allocated
a.out(99502,0x1ed7e4840) malloc: *** set a breakpoint in
malloc_error_break to debug

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x100e7a563
#1  0x100e794e3
#2  0x183eaade3
#3  0x183e73f6f
#4  0x183d80907
#5  0x183c89e37
#6  0x183c8d9bb
#7  0x183cac143
#8  0x100acfa43
#9  0x100acfabf
zsh: abort      ./a.out

% gfortran --version
GNU Fortran (GCC) 15.0.1 20250315 (experimental)

Reply via email to