rc4/asm/rc4-586.pl: allow for 386-only build.
[openssl.git] / crypto / evp / digest.c
index d6abcfe1d6604a47e9b21a859452075ccbeb5a0d..782d3199a5a6acf522952082a6291e36e2a0f7b0 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
@@ -337,8 +344,11 @@ int EVP_Digest(const void *data, size_t count,
 
 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
        {
-       EVP_MD_CTX_cleanup(ctx);
-       OPENSSL_free(ctx);
+       if (ctx)
+               {
+               EVP_MD_CTX_cleanup(ctx);
+               OPENSSL_free(ctx);
+               }
        }
 
 /* This call frees resources associated with the context */