Creating and writing into arrays, CUDA_ERROR_ILLEGAL_ADDRESS

Hi, I started a couple of days ago programming in CUDA.

I call the following function ()

global void opt(){
int arrayLen = toLen+const1;
int *newArray = new int[arrayLen];
for(int i=0;i<arrayLen;i++)
newArray[i]= 2;
}
with paramenters
blockSizeX = 38;
gridSizeX = 38;
gridSizeY = 38;

And what I get is Exception in thread “main” jcuda.CudaException: CUDA_ERROR_ILLEGAL_ADDRESS.

If I run them with lower parameters it works.
I get the errors only if I have the linenewArray[i]= 2, with blocks greater than 38. I am confused. Any help?

UPDATE: Okay, I forgot to free the memory. Now I don’t have the problem anymore.