Fix memory leaking in CUDA code.