From 60748f69d9e21cf4cfd0655a0d7b81a715e9ae04 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Tue, 2 Jul 2019 21:58:15 +0200
Subject: [PATCH 7/7] p11_child: fix a memory leak and other memory mangement
issues
EVP_MD_CTX_create() was called without matching EVP_MD_CTX_destroy().
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
---
src/p11_child/p11_child_openssl.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/p11_child/p11_child_openssl.c b/src/p11_child/p11_child_openssl.c
index 7233f39fd..64d2d759c 100644
--- a/src/p11_child/p11_child_openssl.c
+++ b/src/p11_child/p11_child_openssl.c
@@ -986,9 +986,9 @@ static int do_hash(TALLOC_CTX *mem_ctx, const EVP_MD *evp_md,
done:
+ EVP_MD_CTX_free(md_ctx);
if (ret != EOK) {
free(out);
- EVP_MD_CTX_free(md_ctx);
}
return ret;
@@ -1187,7 +1187,7 @@ static int sign_data(CK_FUNCTION_LIST *module, CK_SESSION_HANDLE session,
CK_RV rv;
CK_RV rv_f;
EVP_PKEY *cert_pub_key = NULL;
- EVP_MD_CTX *md_ctx;
+ EVP_MD_CTX *md_ctx = NULL;
int ret;
const EVP_MD *evp_md = NULL;
CK_BYTE *hash_val = NULL;
@@ -1358,6 +1358,8 @@ static int sign_data(CK_FUNCTION_LIST *module, CK_SESSION_HANDLE session,
ret = EOK;
done:
+ EVP_MD_CTX_destroy(md_ctx);
+ talloc_free(hash_val);
talloc_free(signature);
EVP_PKEY_free(cert_pub_key);
--
2.20.1