Deallocation through a different pointer

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.

4 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

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

Is it possible to get a small reproducer?

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

   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

>>...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.

Connectez-vous pour laisser un commentaire.