cudaFreeArray => Invalid Argument

I’m using a cudaArray to store data and I bind it to a texture.

While the program is running, there’s no problem. Everything is fine.

After the program finishes the computation, a cleanup function calls

cudaFreeArray and I always get the an “Invalid argument”.

The CUDA doc says: “If cudaFreeArray(array) has already been called before, cudaErrorInvalidValue is returned.”

But there is no previous call to cudaFreeArray.

Here is some code:

cudaArray *tdataArray;

texture<float4, 1, cudaReadModeElementType> tdata;

void init()

{

	...

	cutilSafeCall(cudaMallocArray(&tdataArray,  &channelData,  h_dataLength.x, 1));

	cutilSafeCall(cudaMemcpyToArray(tdataArray,  0, 0, data,	h_dataLength.x * sizeof(float4), cudaMemcpyHostToDevice));

	cutilSafeCall(cudaBindTextureToArray(tdata, tdataArray, channelData));

	...

}

void cleanup()

{

	...

	cutilSafeCall(cudaFreeArray(tdataArray));

	cutilSafeCall(cudaUnbindTexture(tdata));

	...

}

I would be very appreciate, if someone can help me figuring out whats the problem.