close device in destructor to prevent I/O error