Fixed potential memory leak when failing to resume a session
diff --git a/ChangeLog b/ChangeLog
index ae02680..ab851fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
= Branch 1.2
Bugfix
+ * Fixed potential memory leak when failing to resume a session
* Minor fixes
Security
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index fd5b5a3..1574217 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -2345,6 +2345,13 @@
return( POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE );
}
+ /* In case we tried to reuse a session but it failed */
+ if( ssl->session_negotiate->peer_cert != NULL )
+ {
+ x509_free( ssl->session_negotiate->peer_cert );
+ free( ssl->session_negotiate->peer_cert );
+ }
+
if( ( ssl->session_negotiate->peer_cert = (x509_cert *) malloc(
sizeof( x509_cert ) ) ) == NULL )
{