From 00fce9cb6cb2b10a5c239fe4853c34648cbd0a53 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Mon, 13 Jan 2025 13:40:39 +0100 Subject: [PATCH] gzip: Move cleanup to separate function to avoid exposing gzip function into wrapper.c Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- include/libssh/crypto.h | 2 ++ src/gzip.c | 14 ++++++++++++++ src/wrapper.c | 14 +------------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/libssh/crypto.h b/include/libssh/crypto.h index a5111802..dad5883d 100644 --- a/include/libssh/crypto.h +++ b/include/libssh/crypto.h @@ -231,6 +231,8 @@ int secure_memcmp(const void *s1, const void *s2, size_t n); ENGINE *pki_get_engine(void); #endif /* HAVE_LIBCRYPTO */ +void compress_cleanup(struct ssh_crypto_struct *crypto); + #ifdef __cplusplus } #endif diff --git a/src/gzip.c b/src/gzip.c index e2d2ac2f..27c8042b 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -260,3 +260,17 @@ decompress_buffer(ssh_session session, ssh_buffer buf, size_t maxlen) SSH_BUFFER_FREE(dest); return 0; } + +void +compress_cleanup(struct ssh_crypto_struct *crypto) +{ + if (crypto->compress_out_ctx) { + deflateEnd(crypto->compress_out_ctx); + } + SAFE_FREE(crypto->compress_out_ctx); + + if (crypto->compress_in_ctx) { + inflateEnd(crypto->compress_in_ctx); + } + SAFE_FREE(crypto->compress_in_ctx); +} diff --git a/src/wrapper.c b/src/wrapper.c index 32f2877f..e3a71622 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -38,10 +38,6 @@ #include #include -#ifdef WITH_ZLIB -#include -#endif - #include "libssh/priv.h" #include "libssh/session.h" #include "libssh/crypto.h" @@ -202,15 +198,7 @@ void crypto_free(struct ssh_crypto_struct *crypto) SAFE_FREE(crypto->secret_hash); } #ifdef WITH_ZLIB - if (crypto->compress_out_ctx) { - deflateEnd(crypto->compress_out_ctx); - } - SAFE_FREE(crypto->compress_out_ctx); - - if (crypto->compress_in_ctx) { - inflateEnd(crypto->compress_in_ctx); - } - SAFE_FREE(crypto->compress_in_ctx); + compress_cleanup(crypto); #endif /* WITH_ZLIB */ SAFE_FREE(crypto->encryptIV); SAFE_FREE(crypto->decryptIV);