From f81088bb80a35644f15bf19fccb71556cee10fe4 Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Tue, 17 Feb 2015 13:10:21 -0500 Subject: [PATCH] Fix a potential memory leak found by find-mem-leak.cocci. --- library/ssl_tls.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index ac35289ab..4eae92faa 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -4063,8 +4063,13 @@ int ssl_set_psk( ssl_context *ssl, const unsigned char *psk, size_t psk_len, ssl->psk = polarssl_malloc( ssl->psk_len ); ssl->psk_identity = polarssl_malloc( ssl->psk_identity_len ); - if( ssl->psk == NULL || ssl->psk_identity == NULL ) + if( ssl->psk == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); + if( ssl->psk_identity == NULL ) + { + polarssl_free( ssl->psk ); + return( POLARSSL_ERR_SSL_MALLOC_FAILED ); + } memcpy( ssl->psk, psk, ssl->psk_len ); memcpy( ssl->psk_identity, psk_identity, ssl->psk_identity_len );