Fix a potential double free in EVP_DigestInit_ex
[openssl.git] / crypto / evp / digest.c
index f89f1c8447d1dd35baf95bc5e8860cbe6849b1dc..0ed884565a2d7f8d75b23f6932e27f5962ab0d0f 100644 (file)
@@ -219,8 +219,10 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
     }
 #endif
     if (ctx->digest != type) {
-        if (ctx->digest && ctx->digest->ctx_size)
+        if (ctx->digest && ctx->digest->ctx_size) {
             OPENSSL_free(ctx->md_data);
+            ctx->md_data = NULL;
+        }
         ctx->digest = type;
         if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {
             ctx->update = type->update;