From a565aceea1d25c94e8f80380f305bf8af4a66d5c Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Wed, 11 Sep 2013 11:45:41 +0200 Subject: [PATCH] Fixed potential memory leak when failing to resume a session --- ChangeLog | 1 + library/ssl_tls.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index ae026801b..ab851fc37 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ PolarSSL ChangeLog = 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 fd5b5a33b..1574217bc 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2345,6 +2345,13 @@ int ssl_parse_certificate( ssl_context *ssl ) 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 ) {