handle deallocate memory on return
I would like avoid to free memory every time that my function return.
I would like avoid to use goto c instruction to jump a code where I
call
EVP_PKEY_free(pkey_fsys);
EVP_PKEY_free(pkey_cert);
to free memory (openssl function)
My code:
if (!(EVP_PKEY_cmp_parameters(pkey_fsys,pkey_cert)))
{
if (pkey_fsys->type != pkey_cert->type)
{
printf("Public keys type mismatch\n");
m_pContext->sendError
(RSA_KEY_MAN_LOAD_CERT,BAD_PUBLIC_KEY);
EVP_PKEY_free(pkey_fsys);
EVP_PKEY_free(pkey_cert);
return;
}
if (BN_cmp(pkey_fsys->pkey.rsa->e,pkey_cert-
pkey.rsa->n) != 0)
{
printf("Public keys exponent mismatch\n");
m_pContext->sendError
(RSA_KEY_MAN_LOAD_CERT,PUBLIC_EXP_MISMATCH);
EVP_PKEY_free(pkey_fsys);
EVP_PKEY_free(pkey_cert);
return;
}
if (BN_cmp(pkey_fsys->pkey.rsa->n,pkey_cert-
pkey.rsa->n) != 0)
{
printf("Public keys modulus mismatch\n");
m_pContext->sendError
(RSA_KEY_MAN_LOAD_CERT,PUBLIC_MOD_MISMATCH);
EVP_PKEY_free(pkey_fsys);
EVP_PKEY_free(pkey_cert);
return;
}
}
EVP_PKEY_free(pkey_fsys);
EVP_PKEY_free(pkey_cert);
}
Please suggest me a better solution.