cuda error : invalid device pointer.

Hi,
I’m working on a GTX 285.
I wrote a fortran code calling many times a C routine, each time with the same input data. In the C routine all the matrices are allocated on the GPU (approximatively 800 Mb). When the C routine is executed for the first time on the GPU everything works fine, but when I call the same routine (with same amount of data) for the second time I got the following error:

cuda error: invalid device pointer
I deallocate all the device pointers at the end of the C routine in this way:
cudaFree(d_Matrix1);


cudaFree(d_Matrixn);
Can anyone hep me??
Thanks in advance

I solved, the problem it was the call cudaFree(d_matrix) because the type it’s cudaPitchedPtr, for a correct free i do :

cudaFree(d_Matrixn.ptr);

By.