]> granicus.if.org Git - esp-idf/commitdiff
components/openssl: fix the SSL_free memory leak
authordongheng <dongheng@espressif.com>
Thu, 22 Sep 2016 10:33:55 +0000 (18:33 +0800)
committerdongheng <dongheng@espressif.com>
Thu, 22 Sep 2016 10:33:55 +0000 (18:33 +0800)
components/openssl/library/ssl_lib.c
components/openssl/platform/ssl_pm.c

index 7e3b4554d696cb097f7d9584424438e249afacfe..20c8931457d28864e31ee2b27c1995eea6a39082 100644 (file)
@@ -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)
index 1ddd1f30d2f80bcd170d6e6efde312fcf609849a..04e370f9fcb3cda180b7d95149f9c053d1a37501 100644 (file)
@@ -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)