Add NULL device protection to free and validate routines for CUDA
and OpenCL backends to prevent errors with gpu_debug targets when
freeing a buffer_t with no device pointer allocated.