From 7eaf4015fa32ec1643b48f51c4f1758770416872 Mon Sep 17 00:00:00 2001 From: Matt Braithwaite Date: Fri, 17 Apr 2015 09:49:34 -0700 Subject: [PATCH] (d2i_SSL_SESSION): Fix a memory leak that occurs on error. Change-Id: I5424617f0b12937f092698d35a99316eb73a6c35 Reviewed-on: https://boringssl-review.googlesource.com/4390 Reviewed-by: Adam Langley --- ssl/ssl_asn1.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ssl/ssl_asn1.c b/ssl/ssl_asn1.c index e4a7f0dc..3bca0c95 100644 --- a/ssl/ssl_asn1.c +++ b/ssl/ssl_asn1.c @@ -410,7 +410,7 @@ static int d2i_SSL_SESSION_get_octet_string(CBS *cbs, uint8_t **out_ptr, } SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const uint8_t **pp, long length) { - SSL_SESSION *ret = NULL; + SSL_SESSION *ret, *allocated = NULL; CBS cbs, session, cipher, session_id, master_key; CBS peer, sid_ctx, peer_sha256, original_handshake_hash; int has_peer, has_peer_sha256, extended_master_secret; @@ -420,8 +420,8 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const uint8_t **pp, long length) { if (a && *a) { ret = *a; } else { - ret = SSL_SESSION_new(); - if (ret == NULL) { + ret = allocated = SSL_SESSION_new(); + if (allocated == NULL) { goto err; } } @@ -585,8 +585,8 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const uint8_t **pp, long length) { return ret; err: - if (a && *a != ret) { - SSL_SESSION_free(ret); + if (allocated) { + SSL_SESSION_free(allocated); } return NULL; }