From 1bfedf9816a12581a35a053b964b40b8182c44d9 Mon Sep 17 00:00:00 2001 From: dongheng Date: Thu, 22 Sep 2016 18:33:55 +0800 Subject: [PATCH] components/openssl: fix the SSL_free memory leak --- components/openssl/library/ssl_lib.c | 2 +- components/openssl/platform/ssl_pm.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/openssl/library/ssl_lib.c b/components/openssl/library/ssl_lib.c index 7e3b4554d6..20c8931457 100644 --- a/components/openssl/library/ssl_lib.c +++ b/components/openssl/library/ssl_lib.c @@ -266,7 +266,7 @@ const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx) */ SSL *SSL_new(SSL_CTX *ctx) { - int ret; + int ret = 0; SSL *ssl; if (!ctx) diff --git a/components/openssl/platform/ssl_pm.c b/components/openssl/platform/ssl_pm.c index 1ddd1f30d2..04e370f9fc 100644 --- a/components/openssl/platform/ssl_pm.c +++ b/components/openssl/platform/ssl_pm.c @@ -162,13 +162,13 @@ void ssl_pm_free(SSL *ssl) { struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - mbedtls_ssl_config_free(&ssl_pm->conf); mbedtls_ctr_drbg_free(&ssl_pm->ctr_drbg); mbedtls_entropy_free(&ssl_pm->entropy); + mbedtls_ssl_config_free(&ssl_pm->conf); mbedtls_ssl_free(&ssl_pm->ssl); - mbedtls_net_free(&ssl_pm->fd); - mbedtls_net_free(&ssl_pm->cl_fd); + ssl_free(ssl_pm); + ssl->ssl_pm = NULL; } int ssl_pm_handshake(SSL *ssl) @@ -383,6 +383,7 @@ void x509_pm_free(X509 *x) x509_pm_unload(x); ssl_free(x->x509_pm); + x->x509_pm = NULL; } int pkey_pm_new(EVP_PKEY *pkey) @@ -443,6 +444,7 @@ void pkey_pm_free(EVP_PKEY *pkey) pkey_pm_unload(pkey); ssl_free(pkey->pkey_pm); + pkey->pkey_pm = NULL; } void ssl_pm_set_bufflen(SSL *ssl, int len)