From f0282e0b50e296f54fdad6a7b7b0eae14b62522b Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Thu, 30 Nov 2017 12:08:22 +0100 Subject: [PATCH] Use mutex on Close() to avoid data races on windows --- serial_windows.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/serial_windows.go b/serial_windows.go index 01fc9a6..e2c40f5 100644 --- a/serial_windows.go +++ b/serial_windows.go @@ -17,9 +17,13 @@ package serial */ -import ("syscall") +import ( + "syscall" + "sync" +) type windowsPort struct { + mu sync.Mutex handle syscall.Handle } @@ -58,8 +62,10 @@ func nativeGetPortsList() ([]string, error) { } func (port *windowsPort) Close() error { + port.mu.Lock() defer func() { port.handle = 0 + port.mu.Unlock() }() if port.handle == 0 { return nil