Ensure we call the cleanup() function when cleaning an EVP_CIPHER_CTX
[openssl.git] / crypto / evp / evp_enc.c
index c1f5d2ca54073d27040e58ca965c839a41ec5425..77dc815dd94201883f74355af2d8114b4580a5d3 100644 (file)
@@ -159,6 +159,8 @@ static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx,
      * (legacy code)
      */
     if (cipher != NULL && ctx->cipher != NULL) {
+        if (ctx->cipher->cleanup != NULL && !ctx->cipher->cleanup(ctx))
+            return 0;
         OPENSSL_clear_free(ctx->cipher_data, ctx->cipher->ctx_size);
         ctx->cipher_data = NULL;
     }