Add a test case for EVP_MD_meth_dup() and EVP_CIPHER_meth_dup()

Check that EVP_MD_meth_free() and EVP_CIPHER_meth_free() does actually
free the data.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16159)
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index 7494c1f..e03e2a2 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -3690,7 +3690,25 @@
     custom_pmeth = NULL;
     return testresult;
 }
-#endif
+
+static int test_evp_md_cipher_meth(void)
+{
+    EVP_MD *md = EVP_MD_meth_dup(EVP_sha256());
+    EVP_CIPHER *ciph = EVP_CIPHER_meth_dup(EVP_aes_128_cbc());
+    int testresult = 0;
+
+    if (!TEST_ptr(md) || !TEST_ptr(ciph))
+        goto err;
+
+    testresult = 1;
+
+ err:
+    EVP_MD_meth_free(md);
+    EVP_CIPHER_meth_free(ciph);
+
+    return testresult;
+}
+#endif /* OPENSSL_NO_DEPRECATED_3_0 */
 
 typedef enum OPTION_choice {
     OPT_ERR = -1,
@@ -3814,6 +3832,7 @@
 
 #ifndef OPENSSL_NO_DEPRECATED_3_0
     ADD_ALL_TESTS(test_custom_pmeth, 12);
+    ADD_TEST(test_evp_md_cipher_meth);
 #endif
 
     return 1;