Fix for crash when disconnecting from serial port