Commit
6725682d introduced a call to ENGINE_get_digest_engine() into
the function asn1_item_digest_with_libctx() to determine whether there
is an ENGINE registered to handle the specified digest. However that
function increases the ref count on the returned ENGINE object, so it
must be freed.
Fixes #12558
[extended tests]
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/12560)
if (EVP_MD_provider(md) == NULL) {
#if !defined(OPENSSL_NO_ENGINE)
- if (ENGINE_get_digest_engine(EVP_MD_type(md)) == NULL)
+ ENGINE *tmpeng = ENGINE_get_digest_engine(EVP_MD_type(md));
+
+ if (tmpeng != NULL)
+ ENGINE_finish(tmpeng);
+ else
#endif
fetched_md = EVP_MD_fetch(libctx, EVP_MD_name(md), propq);
}