https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125782

            Bug ID: 125782
           Summary: Double free failure with associate
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

The following:

module m
  implicit none
contains
  function get_string () result(val)
    character(len=:), allocatable :: val
    val = "needle"
  end function
end module

program main
  use m
  implicit none

  associate (search_string => get_string ())
    if (len (search_string) == 0) STOP 1
    if (search_string // "!" /= "needle!") STOP 2
  end associate
end program

Compiles fine. Fails at run time.

$ gfc associate.f90 
$ ./a.out 
free(): double free detected in tcache 2

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x7fec33f0a0af in ???
#1  0x7fec33f64dcc in ???
#2  0x7fec33f09f8d in ???
#3  0x7fec33ef17b2 in ???
#4  0x7fec33ef2803 in ???
#5  0x7fec33f6f18b in ???
#6  0x7fec33f73c47 in ???
#7  0x40065b in ???
#8  0x400699 in ???
#9  0x7fec33ef3680 in ???
#10  0x7fec33ef3797 in ???
#11  0x4003b4 in ???
#12  0xffffffffffffffff in ???
Aborted                    (core dumped) ./a.out

Reply via email to