erofs-utils: lib: Restore memory address before free()
PATCH 1/1 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, restore the pointer to allocated memory before calling free().
--- lib/rebuild.c | 1 + 1 file changed, 1 insertion(+)
lib/rebuild.c +1 -0
@@ -188,6 +188,7 @@ static int erofs_rebuild_fixup_inode_index(struct erofs_inode *inode) inode->u.chunkformat |= chunkbits - sbi.blkszbits;return 0 ; err: + idx = inode->chunkindexes;free (idx); inode->chunkindexes =NULL ;return ret;
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Hi Sandeep,
Quoted 6 lines · Sandeep Dhavale
We move
idxpointer as we iterate through for loop based oncount. If we error out from the loop, restore the pointer to allocated memory before callingfree().Fixes 39147b48b76d ("erofs-utils: lib: add erofs_rebuild_load_tree() helper")Signed-off-by Sandeep Dhavale <[email protected]>
Thanks for the report!
Quoted 9 lines
--- lib/rebuild.c | 1 + 1 file changed, 1 insertion(+)lib/rebuild.c +0
-0
lib/rebuild.c static int erofs_rebuild_fixup_inode_index(struct erofs_inode *inode) · line 192
Quoted 5 lines
lib/rebuild.c +1
-0@@ -188,6 +188,7 @@ static int erofs_rebuild_fixup_inode_index(struct erofs_inode *inode) inode->u.chunkformat |= chunkbits - sbi.blkszbits;return 0 ; err: + idx = inode->chunkindexes;free (idx);
I think we could just
free(inode->chunkindexes); inode->chunkindexes = NULL;
I will apply like this directly.
Thanks,
Gao Xiang
Quoted 2 lines
lib/rebuild.c +0
-0inode->chunkindexes =NULL ;return ret;
Quoted 30 lines · Gao Xiang
Hi Sandeep,
Quoted 6 lines · Sandeep Dhavale
We move
idxpointer as we iterate through for loop based oncount. If we error out from the loop, restore the pointer to allocated memory before callingfree().Fixes 39147b48b76d ("erofs-utils: lib: add erofs_rebuild_load_tree() helper")Signed-off-by Sandeep Dhavale <[email protected]>Thanks for the report!
Quoted 9 lines
--- lib/rebuild.c | 1 + 1 file changed, 1 insertion(+)lib/rebuild.c +0
-0lib/rebuild.c static int erofs_rebuild_fixup_inode_index(struct erofs_inode *inode) · line 192
Quoted 5 lines
lib/rebuild.c +1
-0@@ -188,6 +188,7 @@ static int erofs_rebuild_fixup_inode_index(struct erofs_inode *inode) inode->u.chunkformat |= chunkbits - sbi.blkszbits;return 0 ; err: + idx = inode->chunkindexes;free (idx);I think we could just
Quoted 5 lines
free(inode->chunkindexes); inode->chunkindexes = NULL;I will apply like this directly.
Hi Gao,
Yes, this looks much better.
Thanks,
Sandeep.
Quoted 5 lines
Thanks,
Gao XiangQuoted 2 lines
lib/rebuild.c +0
-0inode->chunkindexes =NULL ;return ret;