[Help]I can't use the cudaFree function.

I want to write a AES program, but it always return error 77 When I use the cudaFree function in the main function. I don’t know the reason and what should I do to debug it?
-------------------code--------------------------
uint4 * cipher_data_host, * cipher_data_device;
KEY_T * cipher_key_host, * cipher_key_device;

CUDA_CALL(cudaMallocHost(&cipher_data_host, (sizeof(uint4) * NUM_CIPHER_BLOCKS)));
CUDA_CALL(cudaMallocHost(&cipher_key_host, (sizeof(KEY_T) * 11)));
CUDA_CALL(cudaMalloc(&cipher_data_device, (sizeof(uint4) * NUM_CIPHER_BLOCKS)));
CUDA_CALL(cudaMalloc(&cipher_key_device, (sizeof(KEY_T) * 11)));

CUDA_CALL(cudaMemcpy(cipher_data_device, cipher_data_host, (sizeof(uint4) * NUM_CIPHER_BLOCKS),cudaMemcpyHostToDevice));
CUDA_CALL(cudaMemcpy(cipher_key_device, cipher_key_host, (sizeof(KEY_T) * 11), cudaMemcpyHostToDevice));

CUDA_CALL(cudaFree(cipher_data_device)); //returnning error 77 and creating a breakpoint

CUDA_CALL(cudaFree(cipher_key_device));
CUDA_CALL(cudaFreeHost(cipher_data_host));
CUDA_CALL(cudaFreeHost(cipher_key_host));

Error 77 is an illegal address access in device code:

/**
     * The device encountered a load or store instruction on an invalid memory address.
     * This leaves the process in an inconsistent state and any further CUDA work
     * will return the same error. To continue using CUDA, the process must be terminated
     * and relaunched.
     */
    cudaErrorIllegalAddress               =     77,

So the kernel call that you haven’t shown is doing something illegal. Run your code with cuda-memcheck and follow the process here:

https://stackoverflow.com/questions/27277365/unspecified-launch-failure-on-memcpy/27278218#27278218

to identify the specific line that is causing the fault.

Thanks. I did it.