aboutsummaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorRichard Genoud <richard.genoud@posteo.net>2020-11-03 12:11:19 +0100
committerTom Rini <trini@konsulko.com>2020-11-19 09:45:49 -0500
commitccd4c08a452b3703ee16ba730a84b7caadcff97a (patch)
tree549ec9a1c8b5c0e16ba73adf6daaaea7bad065a7 /fs
parent571b67ee1dcb989dc50575f14e87bfdef6bfd8db (diff)
downloadu-boot-ccd4c08a452b3703ee16ba730a84b7caadcff97a.zip
u-boot-ccd4c08a452b3703ee16ba730a84b7caadcff97a.tar.gz
u-boot-ccd4c08a452b3703ee16ba730a84b7caadcff97a.tar.bz2
fs/squashfs: sqfs_probe: fix possible memory leak on error
If SquashFS magic number is invalid, there's a memory leak. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
Diffstat (limited to 'fs')
-rw-r--r--fs/squashfs/sqfs.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index d8d4584..7d6f0e8 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -1090,8 +1090,8 @@ int sqfs_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition
/* Make sure it has a valid SquashFS magic number*/
if (get_unaligned_le32(&sblk->s_magic) != SQFS_MAGIC_NUMBER) {
printf("Bad magic number for SquashFS image.\n");
- ctxt.cur_dev = NULL;
- return -EINVAL;
+ ret = -EINVAL;
+ goto error;
}
ctxt.sblk = sblk;
@@ -1099,12 +1099,16 @@ int sqfs_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition
ret = sqfs_decompressor_init(&ctxt);
if (ret) {
- ctxt.cur_dev = NULL;
- free(ctxt.sblk);
- return -EINVAL;
+ ret = -EINVAL;
+ goto error;
}
return 0;
+error:
+ ctxt.cur_dev = NULL;
+ free(ctxt.sblk);
+ ctxt.sblk = NULL;
+ return ret;
}
static char *sqfs_basename(char *path)