Skip to content

Commit

Permalink
Merge pull request #173 from jes/master
Browse files Browse the repository at this point in the history
unix: nativeOpen: always close the port on errors
  • Loading branch information
cmaglie authored Feb 16, 2024
2 parents 8a31fcb + 0f730e4 commit 1d3c009
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 1d3c009

Please sign in to comment.