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

Deallocation through a different pointer

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
Highlighted
Beginner
3 Views

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

0 Kudos
Highlighted
Employee
3 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
Highlighted
Valued Contributor II
3 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