summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-05-02 16:03:41 +0100
committerGitHub <noreply@github.com>2017-05-02 16:03:41 +0100
commit7849e467579f64ccbbfdc4463af97a215d1ac8e3 (patch)
tree3b88b7a1c492f0c4e86030a1060e5a8223edaf1a
parent9cc0ba6babeaa22c10600255d28d144b377b7709 (diff)
parent2ce2a48f2dfe6a92c0418f5c00e955039fdd0b96 (diff)
downloadlibgit2-7849e467579f64ccbbfdc4463af97a215d1ac8e3.tar.gz
Merge pull request #4229 from pks-t/pks/ssh-memleaks
libssh2 shutdown
-rw-r--r--src/global.c2
-rw-r--r--src/transports/ssh.c14
2 files changed, 14 insertions, 2 deletions
diff --git a/src/global.c b/src/global.c
index e2ad8fe71..afa57e1d6 100644
--- a/src/global.c
+++ b/src/global.c
@@ -22,7 +22,7 @@
git_mutex git__mwindow_mutex;
-#define MAX_SHUTDOWN_CB 8
+#define MAX_SHUTDOWN_CB 9
static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
static git_atomic git__n_shutdown_callbacks;
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 44d02e522..4c55e3f2a 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -9,6 +9,7 @@
#include <libssh2.h>
#endif
+#include "global.h"
#include "git2.h"
#include "buffer.h"
#include "netops.h"
@@ -893,11 +894,22 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p
#endif
}
+#ifdef GIT_SSH
+static void shutdown_ssh(void)
+{
+ libssh2_exit();
+}
+#endif
+
int git_transport_ssh_global_init(void)
{
#ifdef GIT_SSH
+ if (libssh2_init(0) < 0) {
+ giterr_set(GITERR_SSH, "unable to initialize libssh2");
+ return -1;
+ }
- libssh2_init(0);
+ git__on_shutdown(shutdown_ssh);
return 0;
#else