Commit 2785cc8eb2f478dc1bd08d8d8d81c8ada687cbb5

Patrick Steinhardt 2018-03-27T14:49:21

transports: ssh: disconnect session before freeing it The function `ssh_stream_free` takes over the responsibility of closing channels and streams just before freeing their memory, but it does not do so for the session. In fact, we never disconnect the session ourselves at all, as libssh2 will not do so itself upon freeing the structure. Quoting the documentation of `libssh2_session_free`: > Frees all resources associated with a session instance. Typically > called after libssh2_session_disconnect_ex, The missing disconnect probably stems from a misunderstanding what it actually does. As we are already closing the TCP socket ourselves, the assumption was that no additional disconnect is required. But calling `libssh2_session_disconnect` will notify the server that we are cleanly closing the connection, such that the server can free his own resources. Add a call to `libssh2_session_disconnect` to fix that issue. [1]: https://www.libssh2.org/libssh2_session_free.html

1
2
3
4
5
6
7
8
9
10
11
12
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index dcd9b5e..d92cd1f 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -212,6 +212,7 @@ static void ssh_stream_free(git_smart_subtransport_stream *stream)
 	}
 
 	if (s->session) {
+		libssh2_session_disconnect(s->session, "closing transport");
 		libssh2_session_free(s->session);
 		s->session = NULL;
 	}