From 545e830e04d5b857d32ca048923f379de6ee0589 Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Mon, 27 Nov 2017 18:28:08 +0100 Subject: [PATCH] Allow multiple calls to close --- serial_windows.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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) }