Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)

Deallocation through a different pointer

Aaron_S_1
Beginner
252 Views

Has anyone figured out if Intel Inspector will get tricked if memory is deallocated through a different pointer than it was originally associated with? For example if I have a array pointer that I allocate space for, and fill, then I point another array pointer to the original pointer, and deallocate the memory by the new pointer? If I try to deallocate the old pointer I get run time errors, if I don't deallocate it the Inspector reports a memory leak. Is this really a leak? Any help is appreciated.

0 Kudos
3 Replies
Aaron_S_1
Beginner
252 Views

By the way, I'm using the Inspector on Fortran

0 Kudos
Mark_D_Intel
Employee
252 Views

Is it possible to get a small reproducer?

This example works fine for me (compiled on Windows with Composer XE 2013, 64 bit):

[fortran]

   program two_pointer
   integer, pointer :: array1(:),array2(:)
   integer i

   allocate(array1(100))
   do i = 1,100
       array1(i) = i
   end do
   array2 => array1
   deallocate(array2)
   end

[/fortran]

0 Kudos
SergeyKostrov
Valued Contributor II
252 Views
>>...I have a array pointer that I allocate space for, and fill, then I point another array pointer to the original pointer, and >>deallocate the memory by the new pointer? It should work if pArray1[] == pArray2[] >>If I try to deallocate the old pointer I get run time errors, Your description looks right and it should work. However, it is Not clear how you've implemented codes and you could have some logical error when deallocating memory. >>if I don't deallocate it the Inspector reports a memory leak. Is this really a leak? Please see above.
0 Kudos
Reply