Added check to free keypair if already allocated to avoid memory leak

This commit is contained in:
Rahul Tank
2022-09-06 12:07:34 +05:30
parent f9f2bc10d1
commit 7f3c749733
+9
View File
@@ -628,6 +628,10 @@ mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
/* Free the previously allocate keypair */
mbedtls_ecp_keypair_free(&keypair);
mbedtls_ecp_keypair_init(&keypair);
if (( rc = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
@@ -664,6 +668,11 @@ exit:
return 0;
}
void mbedtls_free_keypair(void)
{
mbedtls_ecp_keypair_free(&keypair);
}
#endif
/**