Fix initialization and cleanup code for CUDA-aware code.  Eliminates all resource leaks.