From bfb355c33bb0cbcbb7781044dba995c5bf301e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Sat, 7 Sep 2013 17:27:43 +0200 Subject: [PATCH] Fix memory leak on missed session reuse --- library/ssl_tls.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 2095424f0..910205e89 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2461,6 +2461,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 ); + polarssl_free( ssl->session_negotiate->peer_cert ); + } + if( ( ssl->session_negotiate->peer_cert = (x509_cert *) polarssl_malloc( sizeof( x509_cert ) ) ) == NULL ) {