From c635c55a333a587d9d65c9f0f8e7d1bec6c62da5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 22 Oct 2024 18:45:54 +0100 Subject: [PATCH] connect_to_host(): add missing sk_close on socket error. If we're setting ssh->s to NULL, we ought to free the thing it previously pointed to (having extracted the error message first). At the very least this is a memory leak. But in fact it's worse, because not freeing it also means not cancelling its toplevel callbacks. And if you don't do that, then a failure to set up an SSH connection proxied over another SSH connection will generate two error dialog boxes in succession, the second one from the callback that should have been cancelled here. On Windows that callback never gets called, because we exit the whole process before getting into the main message loop which might run the callback. But on Unix, we do go to the main message loop (we don't have a separate one for the error box), which causes an assertion failure in register_dialog() when the second box finds the DIALOG_SLOT_CONNECTION_FATAL slot already occupied. --- ssh/ssh.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ssh/ssh.c b/ssh/ssh.c index d94145b0..87b1a039 100644 --- a/ssh/ssh.c +++ b/ssh/ssh.c @@ -840,10 +840,12 @@ static char *connect_to_host( false, true, nodelay, keepalive, &ssh->plug, ssh->conf, &ssh->interactor); if ((err = sk_socket_error(ssh->s)) != NULL) { + char *toret = dupstr(err); + sk_close(ssh->s); ssh->s = NULL; seat_notify_remote_exit(ssh->seat); seat_notify_remote_disconnect(ssh->seat); - return dupstr(err); + return toret; } }