Deallocation through a different pointer

Deallocation through a different pointer

imagem de Aaron S.

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 new
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de Aaron S.

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

imagem de mark-dewing (Intel)

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

imagem de Sergey Kostrov

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

Faça login para deixar um comentário.