Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

Memory leak with derived-type allocatables and realloc_lhs

$
0
0

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.

AttachmentSize
Downloadmain.f90746 bytes

Viewing all articles
Browse latest Browse all 2746

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>