Fix an ENGINE leak in asn1_item_digest_with_libctx
[openssl.git] / crypto / asn1 / a_digest.c
index c0c1cda2727c922f5f61f31c45d828455d7532df..3e7b418a1945a3bf8d74791042bf40af6395f015 100644 (file)
@@ -68,7 +68,11 @@ int asn1_item_digest_with_libctx(const ASN1_ITEM *it, const EVP_MD *md,
 
     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);
     }