From: Sandeep Dhavale Date: Tue, 19 Sep 2023 21:02:20 +0000 (-0700) Subject: erofs-utils: lib: Restore memory address before free() X-Git-Tag: v1.8~151 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c60712e595273bb3035d1789a3b8c2a8f8130cb1;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: lib: Restore memory address before free() We move `idx` pointer as we iterate through for loop based on `count`. If we error out from the loop, use the original pointer of allocated memory when calling free(). Fixes: 39147b48b76d ("erofs-utils: lib: add erofs_rebuild_load_tree() helper") Signed-off-by: Sandeep Dhavale Link: https://lore.kernel.org/r/20230919210220.3657736-1-dhavale@google.com Signed-off-by: Gao Xiang --- diff --git a/lib/rebuild.c b/lib/rebuild.c index 9751f0e..5993730 100644 --- a/lib/rebuild.c +++ b/lib/rebuild.c @@ -192,7 +192,7 @@ static int erofs_rebuild_fixup_inode_index(struct erofs_inode *inode) inode->u.chunkformat |= chunkbits - sbi.blkszbits; return 0; err: - free(idx); + free(inode->chunkindexes); inode->chunkindexes = NULL; return ret; }