From 0f730e491f1ffa921f4d83ed57f0d828a9fbe9f4 Mon Sep 17 00:00:00 2001 From: James Stanley Date: Sun, 11 Feb 2024 21:08:52 +0000 Subject: [PATCH] unix: nativeOpen: always close the port on errors --- serial_unix.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serial_unix.go b/serial_unix.go index f6ec896..db6158d 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -249,6 +249,7 @@ func nativeOpen(portName string, mode *Mode) (*unixPort, error) { if mode.InitialStatusBits != nil { status, err := port.getModemBitsStatus() if err != nil { + port.Close() return nil, &PortError{code: InvalidSerialPort, causedBy: err} } if mode.InitialStatusBits.DTR { @@ -262,6 +263,7 @@ func nativeOpen(portName string, mode *Mode) (*unixPort, error) { status &^= unix.TIOCM_RTS } if err := port.setModemBitsStatus(status); err != nil { + port.Close() return nil, &PortError{code: InvalidSerialPort, causedBy: err} } }