From aa62bce083af31e71b8fee7cd57dd93a21a6cd77 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 7 Sep 2014 13:06:52 +0000 Subject: [PATCH] Close the listening socket when a sharing upstream dies. Without this, doing 'Restart Session' on Windows in a session with sharing enabled but no actual sharing being done would crash, because the first incarnation of the session would become an upstream and establish a listening named pipe, which then wouldn't get cleaned up when the session closed, so the restarted session would try to connect to it, triggering a call to plug_accepting on a freed sharestate. [originally from svn r10216] --- sshshare.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sshshare.c b/sshshare.c index bf2a64c2..5b88eb8e 100644 --- a/sshshare.c +++ b/sshshare.c @@ -517,6 +517,10 @@ void sharestate_free(void *v) share_connstate_free(cs); } freetree234(sharestate->connections); + if (sharestate->listensock) { + sk_close(sharestate->listensock); + sharestate->listensock = NULL; + } sfree(sharestate->server_verstring); sfree(sharestate->sockname); sfree(sharestate); @@ -1843,6 +1847,7 @@ static int share_listen_closing(Plug plug, const char *error_msg, ssh_sharing_logf(sharestate->ssh, 0, "listening socket: %s", error_msg); sk_close(sharestate->listensock); + sharestate->listensock = NULL; return 1; }