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

Memory leak with derived-type allocatables and realloc_lhs

Wukie__Nathan
Beginner
2,802 Views

I have a derived-type with an allocatable array component defined as:

module type_one

    type, public :: one_t
        integer, allocatable :: i(:)
    end type one_t

    public operator (+)
    interface operator (+)
        module procedure add
    end interface

contains


    elemental function add(u,v) result(res)
        type(one_t),    intent(in)  :: u,v
        type(one_t) :: res

        res%i = u%i + v%i
    end function

end module type_one

 

Compiling with -assume realloc_lhs and executing the addition operation as follows results in a memory leak:

program mem_leak_test
    use type_one
    implicit none

    type(one_t), allocatable    :: a(:), b(:), c(:)
    integer :: i

    allocate(b(4), c(4))


    do i = 1,4
        allocate(b(i)%i(5))
        allocate(c(i)%i(5))

        b(i)%i = 1.0
        c(i)%i = 2.0
    end do

    a = b + c

    print*, a(1)%i
end program mem_leak_test

This was first observed on OS X using ifort v15.0.3 confirmed on Linux ifort 15.0.2. Valgrind --tool=memcheck produces the following:

==3411== LEAK SUMMARY:
==3411==    definitely lost: 60 bytes in 3 blocks
==3411==    indirectly lost: 0 bytes in 0 blocks
==3411==      possibly lost: 0 bytes in 0 blocks
==3411==    still reachable: 1,136 bytes in 16 blocks
==3411==         suppressed: 0 bytes in 0 blocks

 

This seems related to the following topic:
https://software.intel.com/pt-br/forums/topic/269437

Reproducer is attached.

0 Kudos
24 Replies
Wukie__Nathan
Beginner
430 Views

I am still able to reproduce this issue in ifort 17.0.1 20161005

0 Kudos
Kevin_D_Intel
Employee
430 Views

Yes, sorry, there's been no resolution to this issue yet. We'll keep the post updated when there is.

0 Kudos
Wukie__Nathan
Beginner
430 Views

I am still able to reproduce this issue with ifort 19

0 Kudos
FortranFan
Honored Contributor II
430 Views

Wukie, Nathan wrote:

I am still able to reproduce this issue with ifort 19

I'll suggest you follow up at Intel OSC: https://supporttickets.intel.com/servicecenter?lang=en-US

0 Kudos
Reply