Free dynamically allocated memory before every return statement
in calc_img_key_hash() function.
Verified the secure boot changes using ls1046afrwy board.
Signed-off-by: Kshitiz Varshney <kshitiz.varsh...@nxp.com>
---
 board/freescale/common/fsl_validate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/board/freescale/common/fsl_validate.c 
b/board/freescale/common/fsl_validate.c
index 564a8b3b54..d553bd88a0 100644
--- a/board/freescale/common/fsl_validate.c
+++ b/board/freescale/common/fsl_validate.c
@@ -498,8 +498,11 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv 
*img)
                return ret;
 
        ret = algo->hash_init(algo, &ctx);
-       if (ret)
+       if (ret) {
+               if (ctx)
+                       free(ctx);
                return ret;
+       }
 
        /* Update hash for ESBC key */
 #ifdef CONFIG_KEY_REVOCATION
@@ -518,8 +521,11 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv 
*img)
 
        /* Copy hash at destination buffer */
        ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
-       if (ret)
+       if (ret) {
+               if (ctx)
+                       free(ctx);
                return ret;
+       }
 
        for (i = 0; i < SHA256_BYTES; i++)
                img->img_key_hash[i] = hash_val[i];
-- 
2.25.1

Reply via email to