Skip to content

Commit

Permalink
unix: nativeOpen: always close the port on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jes committed Feb 11, 2024
1 parent 8a31fcb commit 0f730e4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions serial_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}
}
}
Expand Down

0 comments on commit 0f730e4

Please sign in to comment.