aboutsummaryrefslogtreecommitdiff
path: root/libssh/wrapper.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-04 14:15:14 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-04 14:15:14 +0000
commita7fbedf8d61a65c06a2d6f7d9c2f164340e510f9 (patch)
tree6f35e9e4a0628060548e5062cfd6bedaf15a736f /libssh/wrapper.c
parentb3a0c6d9cb93ea6cc2fe650456515ec68a74941a (diff)
downloadlibssh-a7fbedf8d61a65c06a2d6f7d9c2f164340e510f9.tar.gz
libssh-a7fbedf8d61a65c06a2d6f7d9c2f164340e510f9.tar.xz
libssh-a7fbedf8d61a65c06a2d6f7d9c2f164340e510f9.zip
Improve crypto free functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@387 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/wrapper.c')
-rw-r--r--libssh/wrapper.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/libssh/wrapper.c b/libssh/wrapper.c
index a0c62444..46e2b232 100644
--- a/libssh/wrapper.c
+++ b/libssh/wrapper.c
@@ -462,25 +462,27 @@ static struct crypto_struct *cipher_new(int offset){
return cipher;
}
-static void cipher_free(struct crypto_struct *cipher){
+static void cipher_free(struct crypto_struct *cipher) {
#ifdef HAVE_LIBGCRYPT
- unsigned int i;
+ unsigned int i;
#endif
- if (cipher == NULL) {
- return;
- }
- if(cipher->key){
+ if (cipher == NULL) {
+ return;
+ }
+
+ if(cipher->key) {
#ifdef HAVE_LIBGCRYPT
- for (i=0;i<cipher->keylen/sizeof (gcry_cipher_hd_t);i++)
- gcry_cipher_close(cipher->key[i]);
+ for (i = 0; i < (cipher->keylen / sizeof(gcry_cipher_hd_t)); i++) {
+ gcry_cipher_close(cipher->key[i]);
+ }
#elif defined HAVE_LIBCRYPTO
- /* destroy the key */
- memset(cipher->key,0,cipher->keylen);
+ /* destroy the key */
+ memset(cipher->key, 0, cipher->keylen);
#endif
- free(cipher->key);
- }
- free(cipher);
+ SAFE_FREE(cipher->key);
+ }
+ SAFE_FREE(cipher);
}
CRYPTO *crypto_new(void) {
@@ -500,26 +502,22 @@ void crypto_free(CRYPTO *crypto){
if (crypto == NULL) {
return;
}
- if(crypto->server_pubkey)
- free(crypto->server_pubkey);
- if(crypto->in_cipher)
- cipher_free(crypto->in_cipher);
- if(crypto->out_cipher)
- cipher_free(crypto->out_cipher);
- if(crypto->e)
- bignum_free(crypto->e);
- if(crypto->f)
- bignum_free(crypto->f);
- if(crypto->x)
- bignum_free(crypto->x);
- if(crypto->y)
- bignum_free(crypto->y);
- if(crypto->k)
- bignum_free(crypto->k);
- /* lot of other things */
- /* i'm lost in my own code. good work */
- memset(crypto,0,sizeof(*crypto));
- free(crypto);
+
+ SAFE_FREE(crypto->server_pubkey);
+
+ cipher_free(crypto->in_cipher);
+ cipher_free(crypto->out_cipher);
+
+ bignum_free(crypto->e);
+ bignum_free(crypto->f);
+ bignum_free(crypto->x);
+ bignum_free(crypto->y);
+ bignum_free(crypto->k);
+ /* lot of other things */
+ /* i'm lost in my own code. good work */
+ memset(crypto,0,sizeof(*crypto));
+
+ SAFE_FREE(crypto);
}
static int crypt_set_algorithms2(SSH_SESSION *session){