Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
2 Views

Memory leak with -heap-arrays and implied loop

The attached code produces a memory leak when compiled with -heap-arrays with ifort Version 16.0.2.181.

module m
 implicit none

 contains

  subroutine show(text)
   character(len=*), intent(in) :: text(:)
   integer :: i

    write(*,*) (trim(text(i)),i=1,size(text))
  
  end subroutine show

 end module m


program p
 use m
 implicit none
 character(len=100) :: msg(10)

 integer :: i

 msg = "ABC"
 call show(msg)

 !do i=1,10000000
 !  call show(msg)
 !enddo

end program p

 

When run with valgrind (commenting the loop) the erros are

 

$ ifort -g -heap-arrays ml.f90 -o ml
$ valgrind --tool=memcheck --leak-check=full ./ml 
==6290== Memcheck, a memory error detector
==6290== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==6290== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==6290== Command: ./ml
==6290== 
 ABCABCABCABCABCABCABCABCABCABC
==6290== 
==6290== HEAP SUMMARY:
==6290==     in use at exit: 932 bytes in 10 blocks
==6290==   total heap usage: 18 allocs, 8 frees, 13,753 bytes allocated
==6290== 
==6290== 900 bytes in 9 blocks are definitely lost in loss record 2 of 2
==6290==    at 0x4C29F60: malloc (vg_replace_malloc.c:296)
==6290==    by 0x407A4B: for_allocate (in ml)
==6290==    by 0x402534: m_mp_show_ (ml.f90:10)
==6290==    by 0x402773: MAIN__ (ml.f90:25)
==6290==    by 0x4023AD: main (in ml)
==6290== 
==6290== LEAK SUMMARY:
==6290==    definitely lost: 900 bytes in 9 blocks
==6290==    indirectly lost: 0 bytes in 0 blocks
==6290==      possibly lost: 0 bytes in 0 blocks
==6290==    still reachable: 32 bytes in 1 blocks
==6290==         suppressed: 0 bytes in 0 blocks
==6290== Reachable blocks (those to which a pointer was found) are not shown.
==6290== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6290== 
==6290== For counts of detected and suppressed errors, rerun with: -v
==6290== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

 

0 Kudos
2 Replies
Highlighted
Employee
2 Views

Thank you for the report. I

Thank you for the report. I will investigate.

0 Kudos
Highlighted
Employee
2 Views

I confirmed the memory leak

I confirmed the memory leak and escalated this to our Developers. Thank you for the convenient test case. I will keep you updated on the progress of a resolution.

(Internal tracking id: DPD200411297)

0 Kudos