From 9ec9b968f93e4a8e7c90eb1e717f0d7cd4ab722d Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Thu, 26 May 2022 11:09:58 +0100 Subject: Fix a decoder mem leak on an error path If an error condition occurs then the the decoder that was up-refed in ossl_decoder_instance_new can be leaked. Found due to the error report here: https://github.com/openssl/openssl/pull/18355#issuecomment-1138205688 Reviewed-by: Tomas Mraz Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/18410) --- crypto/encode_decode/decoder_lib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crypto/encode_decode') diff --git a/crypto/encode_decode/decoder_lib.c b/crypto/encode_decode/decoder_lib.c index 5dd75ae5f2..9dcbab1077 100644 --- a/crypto/encode_decode/decoder_lib.c +++ b/crypto/encode_decode/decoder_lib.c @@ -228,10 +228,6 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_MALLOC_FAILURE); return 0; } - if (!OSSL_DECODER_up_ref(decoder)) { - ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_INTERNAL_ERROR); - goto err; - } prov = OSSL_DECODER_get0_provider(decoder); libctx = ossl_provider_libctx(prov); @@ -263,6 +259,10 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, = ossl_property_get_string_value(libctx, prop); } + if (!OSSL_DECODER_up_ref(decoder)) { + ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_INTERNAL_ERROR); + goto err; + } decoder_inst->decoder = decoder; decoder_inst->decoderctx = decoderctx; return decoder_inst; -- cgit v1.2.1