Skip to contentSkip to conversation

fs/squashfs: Ensure memory is freed by using unwind goto

PATCH In review Andrew Goodbody 4 participants 4 messages Oct 2, 2025 – Oct 11, 2025 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/squashfs: Ensure memory is freed by using unwind goto

Returning immediately from sqfs_read_nest is not consistent with other error checks in this function and can lead to memory leaks. Instead use the unwind goto used elsewhere to ensure that the memory is freed.

This issue was found by Smatch.

---
 fs/squashfs/sqfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/squashfs/sqfs.c +4 -2
index 2dcdd60f68343f801bd73e318568fb030434ed31..4d3d83b75873f4d66f2dbd544ae6715f66f5d289 100644
@@ -1584,8 +1584,10 @@ static int sqfs_read_nest(const char *filename, void *buf, loff_t offset,
 	table_offset = frag_entry.start - (start * ctxt.cur_dev->blksz);
 	n_blks = DIV_ROUND_UP(table_size + table_offset, ctxt.cur_dev->blksz);
 
-	if (__builtin_mul_overflow(n_blks, ctxt.cur_dev->blksz, &buf_size))
-		return -EINVAL;
+	if (__builtin_mul_overflow(n_blks, ctxt.cur_dev->blksz, &buf_size)) {
+		ret = -EINVAL;
+		goto out;
+	}
 
 	fragment = malloc_cache_aligned(buf_size);
 

---
base-commit: da47ddebd16a7e1047da8537fbf01558d2a89fcf
change-id: 20251002-fs_squashfs-ef3fa4928e33

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Goodbody

Hello, Andrew

Quoted 8 lines · Andrew Goodbody

Returning immediately from sqfs_read_nest is not consistent with other error checks in this function and can lead to memory leaks. Instead use the unwind goto used elsewhere to ensure that the memory is freed.

This issue was found by Smatch.

---

Thanks for this fix!

Signature · 2 lines
Best regards,
João Marcos Costa
#3 lore raw
In reply to Andrew Goodbody
Quoted 8 lines · Andrew Goodbody

Returning immediately from sqfs_read_nest is not consistent with other error checks in this function and can lead to memory leaks. Instead use the unwind goto used elsewhere to ensure that the memory is freed.

This issue was found by Smatch.

[...]

Applied to u-boot/master, thanks!

[1/1] fs/squashfs: Ensure memory is freed by using unwind goto

      commit: 87b7eaf3244e1a991404602c3422a4ce06bfae55
Signature · 1 line
Tom