Increment pkey references count

This commit is contained in:
Tesfa Mael 2019-12-19 13:49:46 -08:00
parent 48e59eaeb1
commit 99a7aff31e
2 changed files with 13 additions and 1 deletions

View File

@ -16132,7 +16132,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
{
WOLFSSL_ENTER("EVP_MD_CTX_cleanup");
if (ctx->pctx != NULL)
XFREE(ctx->pctx, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
wolfSSL_EVP_PKEY_CTX_free(ctx->pctx);
if (ctx->macType == (NID_hmac & 0xFF)) {
wc_HmacFree(&ctx->hash.hmac);

View File

@ -918,6 +918,7 @@ int wolfSSL_EVP_PKEY_CTX_free(WOLFSSL_EVP_PKEY_CTX *ctx)
WOLFSSL_EVP_PKEY_CTX *wolfSSL_EVP_PKEY_CTX_new(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_ENGINE *e)
{
WOLFSSL_EVP_PKEY_CTX* ctx;
int type = NID_undef;
if (pkey == NULL) return 0;
if (e != NULL) return 0;
@ -931,7 +932,18 @@ WOLFSSL_EVP_PKEY_CTX *wolfSSL_EVP_PKEY_CTX_new(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_E
#if !defined(NO_RSA) && !defined(HAVE_USER_RSA)
ctx->padding = RSA_PKCS1_PADDING;
#endif
type = wolfSSL_EVP_PKEY_type(pkey->type);
if ((type == EVP_PKEY_RSA) ||
(type == EVP_PKEY_DSA) ||
(type == EVP_PKEY_EC)) {
if (wc_LockMutex(&pkey->refMutex) != 0) {
WOLFSSL_MSG("Couldn't lock pkey mutex");
}
pkey->references++;
wc_UnLockMutex(&pkey->refMutex);
}
return ctx;
}