Skip to content

Commit 2ce2a48

Browse files
committed
transports: ssh: clean up after libssh2 on exit
After calling `libssh2_init`, we need to clean up after the library by executing `libssh2_exit` as soon as we exit. Register a shutdown handler to do so which simply calls `libssh2_exit`. This fixes several memory leaks.
1 parent 8c02735 commit 2ce2a48

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
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: 9 additions & 0 deletions
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,6 +894,13 @@ 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
@@ -901,6 +909,7 @@ int git_transport_ssh_global_init(void)
901909
return -1;
902910
}
903911

912+
git__on_shutdown(shutdown_ssh);
904913
return 0;
905914

906915
#else

0 commit comments

Comments
 (0)