If the device is detached during config read, the config can be NULL. Check
Make sure that we close the device handles as we go, to save number of open
files. When the backend is freed any leftover file handles will get freed, so
it is not absolutely needed to close the device handle in every case.