From: Kovalev Vasiliy Date: Thu, 4 May 2023 12:12:33 +0000 (+0400) Subject: Fix memory leak in engine_cleanup_add_first() X-Git-Tag: openssl-3.2.0-alpha1~899 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c63b14296f117b07781509ced529a8955d78fb9;p=thirdparty%2Fopenssl.git Fix memory leak in engine_cleanup_add_first() Fixes #20870 Reviewed-by: Tom Cosgrove Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/20880) --- diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c index 40e0413a265..b10751336fa 100644 --- a/crypto/engine/eng_lib.c +++ b/crypto/engine/eng_lib.c @@ -140,8 +140,9 @@ void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb) if (!int_cleanup_check(1)) return; item = int_cleanup_item(cb); - if (item) - sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0); + if (item != NULL) + if (sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0) <= 0) + OPENSSL_free(item); } void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)