From: Rich Salz Date: Sun, 26 Apr 2015 02:55:36 +0000 (-0400) Subject: Free malloc data on encoding errors. X-Git-Tag: OpenSSL_1_1_0-pre1~1275 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a194ee7b9aab3c8fae2d5b840ce1ae81de940b48;p=oweals%2Fopenssl.git Free malloc data on encoding errors. Reviewed-by: Richard Levitte --- diff --git a/apps/s_server.c b/apps/s_server.c index 88309a6b9c..da725e7a4d 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -3169,6 +3169,7 @@ static int add_session(SSL *ssl, SSL_SESSION *session) sess->derlen = i2d_SSL_SESSION(session, NULL); if (sess->derlen < 0) { BIO_printf(bio_err, "Error encoding session\n"); + OPENSSL_free(sess); return 0; } @@ -3176,10 +3177,8 @@ static int add_session(SSL *ssl, SSL_SESSION *session) sess->der = OPENSSL_malloc(sess->derlen); if (!sess->id || !sess->der) { BIO_printf(bio_err, "Out of memory adding to external cache\n"); - if (sess->id) - OPENSSL_free(sess->id); - if (sess->der) - OPENSSL_free(sess->der); + OPENSSL_free(sess->id); + OPENSSL_free(sess->der); OPENSSL_free(sess); return 0; } @@ -3187,7 +3186,10 @@ static int add_session(SSL *ssl, SSL_SESSION *session) /* Assume it still works. */ if (i2d_SSL_SESSION(session, &p) != sess->derlen) { - BIO_printf(bio_err, "Error encoding session\n"); + BIO_printf(bio_err, "Re-encoding session strangeness\n"); + OPENSSL_free(sess->id); + OPENSSL_free(sess->der); + OPENSSL_free(sess); return 0; }