From 80f5105dad377522f86abf89d6362bfa4b3dc763 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 12 Sep 2021 09:52:46 +0100 Subject: [PATCH] sshproxy: keep addr and free it on close. The caller of new_connection has relinquished ownership of the SockAddr it passes in. So the receiver of that SockAddr must remember to free it, or else we leak memory. (Additionally, this means SshProxy will be able to remember the address during its run, e.g. to use in calls to its Plug. But that's not implemented yet.) --- sshproxy.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sshproxy.c b/sshproxy.c index f36a2a9b..18a1b9da 100644 --- a/sshproxy.c +++ b/sshproxy.c @@ -65,6 +65,8 @@ typedef struct SshProxy { bufchain ssh_to_socket; bool rcvd_eof_ssh_to_socket, sent_eof_ssh_to_socket; + SockAddr *addr; + /* Traits implemented: we're a Socket from the point of view of * the client connection, and a Seat from the POV of the SSH * backend we instantiate. */ @@ -86,6 +88,7 @@ static void sshproxy_close(Socket *s) { SshProxy *sp = container_of(s, SshProxy, sock); + sk_addr_free(sp->addr); sfree(sp->errmsg); conf_free(sp->conf); if (sp->backend) @@ -460,6 +463,8 @@ Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname, psb_init(&sp->psb); bufchain_init(&sp->ssh_to_socket); + sp->addr = addr; + sp->conf = conf_new(); /* Try to treat proxy_hostname as the title of a saved session. If * that fails, set up a default Conf of our own treating it as a