Skip to content

Commit 7849e46

Browse files
authored
Merge pull request libgit2#4229 from pks-t/pks/ssh-memleaks
libssh2 shutdown
2 parents 9cc0ba6 + 2ce2a48 commit 7849e46

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/global.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
git_mutex git__mwindow_mutex;
2424

25-
#define MAX_SHUTDOWN_CB 8
25+
#define MAX_SHUTDOWN_CB 9
2626

2727
static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
2828
static git_atomic git__n_shutdown_callbacks;

src/transports/ssh.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <libssh2.h>
1010
#endif
1111

12+
#include "global.h"
1213
#include "git2.h"
1314
#include "buffer.h"
1415
#include "netops.h"
@@ -893,11 +894,22 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p
893894
#endif
894895
}
895896

897+
#ifdef GIT_SSH
898+
static void shutdown_ssh(void)
899+
{
900+
libssh2_exit();
901+
}
902+
#endif
903+
896904
int git_transport_ssh_global_init(void)
897905
{
898906
#ifdef GIT_SSH
907+
if (libssh2_init(0) < 0) {
908+
giterr_set(GITERR_SSH, "unable to initialize libssh2");
909+
return -1;
910+
}
899911

900-
libssh2_init(0);
912+
git__on_shutdown(shutdown_ssh);
901913
return 0;
902914

903915
#else

0 commit comments

Comments
 (0)