Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

crash deallocating passed pointers

martymike
Novice
258 Views

We want to create a structure holding strings that vary greatly in length that can be modified during program execution. So we are using deferred length pointers. However, we are running into a problem deallocating them later. Below is a greatly simplified program that demonstrates the issue. The deallocate in the main program works. The one in subroutine a crashes.


      
      character(:), pointer :: ptr1
      character(:), pointer :: ptr2
      integer ierr
      
      allocate(character(12) :: ptr1, stat = ierr)
      ptr1 = "ABCDEFGHIJKLM"
      ptr2 => ptr1
      deallocate(ptr2)
      allocate(character(12) :: ptr1, stat = ierr)
      ptr1 = "MLKJIHGFEDCBA"
      call a(ptr1)
      
      contains
      
      subroutine a(ptr)
      character(:), pointer :: ptr
      
      ptr2 => ptr
      deallocate(ptr2)
      
      end subroutine a
      end

 

0 Kudos
2 Replies
martymike
Novice
258 Views

Forgot to mention, running IVF 15

0 Kudos
Kevin_D_Intel
Employee
258 Views

It appears this should work when using ptr2. It also fails with the 16.0 compiler. Deallocation is successful inside the contained routine when using the dummy argument itself. I submitted this to Development.

(Internal tracking id: DPD200377888)

0 Kudos
Reply