Fixed potential memory leak when failing to resume a session

Conflicts:
	ChangeLog
	library/ssl_tls.c
diff --git a/ChangeLog b/ChangeLog
index 9e8eb0b..60ef749 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 PolarSSL ChangeLog
 
 = Branch 1.1
+Bugfix
+   * Fixed potential memory leak when failing to resume a session
+
 Security
    * Potential buffer-overflow for ssl_read_record() (independently found by
      both TrustInSoft and Paul Brodeur of Leviathan Security Group)
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index a5d1cb1..73a6604 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -1444,6 +1444,13 @@
         return( POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE );
     }
 
+    /* In case we tried to reuse a session but it failed */
+    if( ssl->peer_cert != NULL )
+    {
+        x509_free( ssl->peer_cert );
+        free( ssl->peer_cert );
+    }
+
     if( ( ssl->peer_cert = (x509_cert *) malloc(
                     sizeof( x509_cert ) ) ) == NULL )
     {