Fix memory leak: free up ENGINE functional reference if digest is not
[openssl.git] / crypto / evp / digest.c
index d6abcfe1d6604a47e9b21a859452075ccbeb5a0d..982ba2b136a9a74ad04c24bf2a491d45fd3f4e84 100644 (file)
@@ -175,6 +175,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
                                {
                                /* Same comment from evp_enc.c */
                                EVPerr(EVP_F_EVP_DIGESTINIT_EX,EVP_R_INITIALIZATION_ERROR);
+                               ENGINE_finish(impl);
                                return 0;
                                }
                        /* We'll use the ENGINE's private digest definition */
@@ -203,6 +204,12 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
                        {
                        ctx->update = type->update;
                        ctx->md_data=OPENSSL_malloc(type->ctx_size);
+                       if (ctx->md_data == NULL)
+                               {
+                               EVPerr(EVP_F_EVP_DIGESTINIT_EX,
+                                                       ERR_R_MALLOC_FAILURE);
+                               return 0;
+                               }
                        }
                }
 #ifndef OPENSSL_NO_ENGINE