From 2c1c81aecdc28f4d5a5221cad584cb1a379b36ab Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Wed, 2 Aug 2017 19:32:12 +0200 Subject: [PATCH] Use defer for closing the listenmutex --- sshd.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sshd.go b/sshd.go index 7809e93..58ee922 100644 --- a/sshd.go +++ b/sshd.go @@ -180,18 +180,19 @@ func main() { go func() { err := client.SshConn.Wait() client.ListenMutex.Lock() + defer client.ListenMutex.Unlock() client.Stopping = true if *verbose { log.Printf("[%s] SSH connection closed: %s", client.Name, err) } + for bind, listener := range client.Listeners { if *verbose { log.Printf("[%s] Closing listener bound to %s", client.Name, bind) } listener.Close() } - client.ListenMutex.Unlock() }() // Accept requests & channels