Memory alignment issue Wrong pointers after memory allocation

Have such piece of code:

__device__ void make_box2ind(double *x, int dim, int N, int comp1, int comp2, int bs,int inveps, int *ind, int *box, int *lis) {

	printf("Thread %d make_box2ind started \n", threadIdx.x);

	int d, i, ix, iy, ixy;

	int ib = bs - 1;

	double *xx;

	xx = (double *) malloc(dim*N);

	printf("Make_box2ind mem allocated \n");

	memcpy(xx, x, N * dim * sizeof(double));

	printf("make_box2ind mem copied \n");




This function is called from global one, that is runned by only one thread, so program is serial.

And all is going wrong after declaration of those integers:

and then BAM!

variable dim changed it value from 4 to -1 without any reason.

However, if I’ll remove those declarations, another issue comes:

and then

dim changed again.

Tried both toolkits: 3.2 and 4.0 on GForce GTX550Ti with sm_20.

I can’t even imagine: what’s wrong with that. Seems like problem with alignment, but how to resolve that???

Will be very appreciate for your advices.