Fixes #167: Check if driver is unloaded when freeing array

Global variables are freed after the driver has been unloaded. This fix
throws exceptions when `cudaFree` returns errors which are not
`cudaErrorCudartUnloading`.