From a5bb071927dd983a63c3c3a33a031b33c81e13ba Mon Sep 17 00:00:00 2001 From: shchmue Date: Fri, 25 Oct 2019 11:59:34 -0600 Subject: [PATCH] keys: Fix potential memory leak in _nca_process --- source/keys/keys.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/keys/keys.c b/source/keys/keys.c index e412ecd..84ca01a 100644 --- a/source/keys/keys.c +++ b/source/keys/keys.c @@ -1130,8 +1130,10 @@ static void *_nca_process(u32 hk_ks1, u32 hk_ks2, FIL *fp, u32 key_offset, u32 l u8 *temp_file = (u8*)malloc(0x400), ctr[0x10] = {0}; - if (f_lseek(fp, 0x200) || f_read(fp, temp_file, 0x400, &read_bytes) || read_bytes != 0x400) + if (f_lseek(fp, 0x200) || f_read(fp, temp_file, 0x400, &read_bytes) || read_bytes != 0x400) { + free(temp_file); return NULL; + } se_aes_xts_crypt(hk_ks1, hk_ks2, 0, 1, temp_file, temp_file, 0x200, 2); // both 1.x and 2.x use master_key_00 temp_file[0x20] -= temp_file[0x20] ? 1 : 0;