cudaFree frees host memory

So I have this code and when I free dev_result_1 the g_result_1 is also freed. Is this a valid behaviour for CUDA?

cudaMalloc((void**)&dev_result_1, g_result_size)
g_result_1 = malloc.........
cudaMemcpy(g_result_1, dev_result_1, g_result_size, cudaMemcpyDeviceToHost);

Not, it’s not valid behavior for CUDA.

I also don’t think it is actually due to CUDA. It’s more likely a bug in your code, such as stack corruption.

It’s impossible to say without a reproducer.