diff --git a/serial_windows.go b/serial_windows.go index 6ccaa86..01fc9a6 100644 --- a/serial_windows.go +++ b/serial_windows.go @@ -17,7 +17,7 @@ package serial */ -import "syscall" +import ("syscall") type windowsPort struct { handle syscall.Handle @@ -58,6 +58,12 @@ func nativeGetPortsList() ([]string, error) { } func (port *windowsPort) Close() error { + defer func() { + port.handle = 0 + }() + if port.handle == 0 { + return nil + } return syscall.CloseHandle(port.handle) }