diff mbox series

fs/squashfs: sqfs_close/sqfs_read_sblk: set ctxt.sblk to NULL after free

Message ID 20201124170752.18897-1-richard.genoud@posteo.net
State Accepted
Commit 7e932ac790b3615a67a3c24041c194aa748c0d98
Delegated to: Tom Rini
Headers show
Series fs/squashfs: sqfs_close/sqfs_read_sblk: set ctxt.sblk to NULL after free | expand

Commit Message

Richard Genoud Nov. 24, 2020, 5:07 p.m. UTC
This will prevent a double free error if sqfs_close() is called twice.

Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
---
 fs/squashfs/sqfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tom Rini Dec. 3, 2020, 4:59 p.m. UTC | #1
On Tue, Nov 24, 2020 at 06:07:52PM +0100, Richard Genoud wrote:

> This will prevent a double free error if sqfs_close() is called twice.
> 
> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index 15208b4dab0..4e6b6058f97 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -49,6 +49,7 @@  static int sqfs_read_sblk(struct squashfs_super_block **sblk)
 
 	if (sqfs_disk_read(0, 1, *sblk) != 1) {
 		free(*sblk);
+		sblk = NULL;
 		return -EINVAL;
 	}
 
@@ -1542,9 +1543,10 @@  free_strings:
 
 void sqfs_close(void)
 {
+	sqfs_decompressor_cleanup(&ctxt);
 	free(ctxt.sblk);
+	ctxt.sblk = NULL;
 	ctxt.cur_dev = NULL;
-	sqfs_decompressor_cleanup(&ctxt);
 }
 
 void sqfs_closedir(struct fs_dir_stream *dirs)