summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Riordan <mriordan@ipswitch.com>2011-05-18 16:18:39 -0500
committerAndreas Schneider <asn@cryptomilk.org>2011-05-27 11:45:45 +0200
commitdcea8db6b221ab812c66bfabd3c0a00aada78c96 (patch)
tree1e2963b588863360df511e161a5643b2ac3a734f
parent809b3adeba94c1128c7a2ed5354ade305156b8b8 (diff)
downloadlibssh-dcea8db6b221ab812c66bfabd3c0a00aada78c96.tar.gz
libssh-dcea8db6b221ab812c66bfabd3c0a00aada78c96.tar.xz
libssh-dcea8db6b221ab812c66bfabd3c0a00aada78c96.zip
Fix memory leak when compression is used
Signed-off-by: Mark Riordan <mriordan@ipswitch.com> Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/wrapper.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/wrapper.c b/src/wrapper.c
index 6b88e0d2..11482f88 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -38,6 +38,10 @@
#include <stdio.h>
#include <string.h>
+#ifdef WITH_LIBZ
+#include <zlib.h>
+#endif
+
#include "libssh/priv.h"
#include "libssh/session.h"
#include "libssh/crypto.h"
@@ -82,7 +86,7 @@ static void cipher_free(struct crypto_struct *cipher) {
}
struct ssh_crypto_struct *crypto_new(void) {
- struct ssh_crypto_struct *crypto;
+ struct ssh_crypto_struct *crypto;
crypto = malloc(sizeof(struct ssh_crypto_struct));
if (crypto == NULL) {
@@ -108,6 +112,18 @@ void crypto_free(struct ssh_crypto_struct *crypto){
bignum_free(crypto->y);
bignum_free(crypto->k);
/* lot of other things */
+
+#ifdef WITH_LIBZ
+ if (crypto->compress_out_ctx &&
+ (deflateEnd(crypto->compress_out_ctx) != 0)) {
+ inflateEnd(crypto->compress_out_ctx);
+ }
+ if (crypto->compress_in_ctx &&
+ (deflateEnd(crypto->compress_in_ctx) != 0)) {
+ inflateEnd(crypto->compress_in_ctx);
+ }
+#endif
+
/* i'm lost in my own code. good work */
memset(crypto,0,sizeof(*crypto));