fix missing mutex unlock

Fixes a missing mutex unlock on an out of memory error
in ltc_ecc_fp_save_state().

Originates from: 4af447d408

Fixes #571

Comment by sj:
This patch version slightly deviates from the original patch to OP-TEE
since we don't call `XFREE(NULL)` as there exist implementations of
`free()` that don't support it.

Signed-off-by: Ryan Cai <ycaibb@gmail.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Modified-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
ycaibb 2021-09-10 19:44:54 +08:00 committed by Jamie Reece Wilson
parent 03b3538830
commit 6741c76089

View File

@ -1429,8 +1429,10 @@ int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen)
* and the mu INTEGER
*/
cache_entry = XCALLOC(FP_ENTRIES*(2*(1U<<FP_LUT)+4)+3, sizeof(ltc_asn1_list));
if (cache_entry == NULL)
if (cache_entry == NULL) {
LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
return CRYPT_MEM;
}
j = 1; /* handle the zero'th element later */
LTC_SET_ASN1(cache_entry, j++, LTC_ASN1_SHORT_INTEGER, &fp_entries, 1);