From: Matt Caswell Date: Thu, 30 Apr 2015 13:51:10 +0000 (+0100) Subject: Fix memory leaks in BIO_dup_chain() X-Git-Tag: OpenSSL_1_1_0-pre1~1012 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=aec54108ef0d469964505ac1f77984f19099ec05;p=oweals%2Fopenssl.git Fix memory leaks in BIO_dup_chain() This fixes a memory leak that can occur whilst duplicating a BIO chain if the call to CRYPTO_dup_ex_data() fails. It also fixes a second memory leak where if a failure occurs after successfully creating the first BIO in the chain, then the beginning of the new chain was not freed. With thanks to the Open Crypto Audit Project for reporting this issue. Reviewed-by: Stephen Henson --- diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 19cd06983f..cc859da740 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -535,8 +535,10 @@ BIO *BIO_dup_chain(BIO *in) /* copy app data */ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new_bio->ex_data, - &bio->ex_data)) + &bio->ex_data)) { + BIO_free(new_bio); goto err; + } if (ret == NULL) { eoc = new_bio; @@ -548,7 +550,8 @@ BIO *BIO_dup_chain(BIO *in) } return (ret); err: - BIO_free(ret); + BIO_free_all(ret); + return (NULL); }