From d51db08c5c485d3c3ee2cc6a0cb5fc5dda55fc35 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Fri, 10 Feb 2012 12:35:22 -0800 Subject: [PATCH] libfreerdp-core: fix memory leaks and double free --- libfreerdp-core/crypto.c | 6 ++++++ libfreerdp-core/freerdp.c | 4 +++- libfreerdp-core/rdp.c | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libfreerdp-core/crypto.c b/libfreerdp-core/crypto.c index 2d24da55f..b79ac7aff 100644 --- a/libfreerdp-core/crypto.c +++ b/libfreerdp-core/crypto.c @@ -107,6 +107,8 @@ void crypto_des3_decrypt(CryptoDes3 des3, uint32 length, const uint8* in_data, u void crypto_des3_free(CryptoDes3 des3) { + if (des3 == NULL) + return; EVP_CIPHER_CTX_cleanup(&des3->des3_ctx); xfree(des3); } @@ -135,6 +137,8 @@ void crypto_hmac_final(CryptoHmac hmac, uint8* out_data, uint32 length) void crypto_hmac_free(CryptoHmac hmac) { + if (hmac == NULL) + return; HMAC_CTX_cleanup(&hmac->hmac_ctx); xfree(hmac); } @@ -149,6 +153,8 @@ CryptoCert crypto_cert_read(uint8* data, uint32 length) void crypto_cert_free(CryptoCert cert) { + if (cert == NULL) + return; X509_free(cert->px509); xfree(cert); } diff --git a/libfreerdp-core/freerdp.c b/libfreerdp-core/freerdp.c index 310982240..0b0c418c6 100644 --- a/libfreerdp-core/freerdp.c +++ b/libfreerdp-core/freerdp.c @@ -192,11 +192,13 @@ void freerdp_context_new(freerdp* instance) void freerdp_context_free(freerdp* instance) { + if (instance->context == NULL) + return; IFCALL(instance->ContextFree, instance, instance->context); - rdp_free(instance->context->rdp); graphics_free(instance->context->graphics); xfree(instance->context); + instance->context = NULL; } uint32 freerdp_error_info(freerdp* instance) diff --git a/libfreerdp-core/rdp.c b/libfreerdp-core/rdp.c index 8d499e854..399d8c199 100644 --- a/libfreerdp-core/rdp.c +++ b/libfreerdp-core/rdp.c @@ -902,6 +902,11 @@ void rdp_free(rdpRdp* rdp) { if (rdp != NULL) { + crypto_rc4_free(rdp->rc4_decrypt_key); + crypto_rc4_free(rdp->rc4_encrypt_key); + crypto_des3_free(rdp->fips_encrypt); + crypto_des3_free(rdp->fips_decrypt); + crypto_hmac_free(rdp->fips_hmac); extension_free(rdp->extension); settings_free(rdp->settings); transport_free(rdp->transport);