1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-08 08:58:00 +00:00

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.
This commit is contained in:
Simon Tatham 2024-10-22 18:45:54 +01:00
parent 8e6797ecfd
commit c635c55a33

View File

@ -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;
}
}