HardwareSerial::end does not check state of begun, and therefore calls close with a null pointer if begin() function was not previously called.