From 01470097c6ff22b3c1a8c4383ae08a2ad3ce0ff8 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Mon, 3 Mar 2008 14:51:35 +0000 Subject: fix bug #0000002 : in_socket_buffer and out_socket_buffer memleak + "g" and "p" O(1) memleak. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@134 7dcaeef0-15fb-0310-b436-a5af3365683c --- libssh/dh.c | 15 ++++++++++++--- libssh/init.c | 1 + libssh/session.c | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'libssh') diff --git a/libssh/dh.c b/libssh/dh.c index 937ca6a4..a7f4e775 100644 --- a/libssh/dh.c +++ b/libssh/dh.c @@ -65,6 +65,7 @@ static unsigned char p_value[] = { static unsigned long g_int = 2 ; /* G is defined as 2 by the ssh2 standards */ static bignum g; static bignum p; +static int ssh_crypto_inited=0; /* maybe it might be enhanced .... */ /* XXX Do it. */ @@ -84,10 +85,10 @@ int ssh_get_random(void *where, int len, int strong){ } } + /* it inits the values g and p which are used for DH key agreement */ void ssh_crypto_init(){ - static int init=0; - if(!init){ + if(ssh_crypto_inited == 0){ #ifdef HAVE_LIBGCRYPT gcry_check_version(NULL); if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P,0)) @@ -105,10 +106,18 @@ void ssh_crypto_init(){ bignum_bin2bn(p_value,P_LEN,p); OpenSSL_add_all_algorithms(); #endif - init++; + ssh_crypto_inited++; } } +void ssh_crypto_finalize(){ + if(ssh_crypto_inited){ + bignum_free(g); + bignum_free(p); + ssh_crypto_inited=0; + } +} + /* prints the bignum on stderr */ void ssh_print_bignum(char *which,bignum num){ #ifdef HAVE_LIBGCRYPT diff --git a/libssh/init.c b/libssh/init.c index e7f27bc1..f1ae11f0 100644 --- a/libssh/init.c +++ b/libssh/init.c @@ -25,6 +25,7 @@ MA 02111-1307, USA. */ int ssh_finalize() { + ssh_crypto_finalize(); #ifdef HAVE_LIBGCRYPT gcry_control(GCRYCTL_TERM_SECMEM); #elif defined HAVE_LIBCRYPTO diff --git a/libssh/session.c b/libssh/session.c index bb7858ef..1f19640d 100644 --- a/libssh/session.c +++ b/libssh/session.c @@ -58,6 +58,10 @@ void ssh_cleanup(SSH_SESSION *session){ buffer_free(session->in_buffer); if(session->out_buffer) buffer_free(session->out_buffer); + if(session->in_socket_buffer) + buffer_free(session->in_socket_buffer); + if(session->out_socket_buffer) + buffer_free(session->out_socket_buffer); if(session->banner) free(session->banner); if(session->options) -- cgit v1.2.3