[PATCH v2] lib: decompress_unxz: Make it obvious that there is no memory leak
From: Ivy Lopez
Date: Mon Aug 31 2026 - 22:03:41 EST
Calling __decompress() or unxz() with fill == NULL && flush == NULL &&
in == NULL is invalid, thus there were no memory leaks even though it
might have looked like that. Move the conditional free() calls so that
it's obvious that there are no leaks.
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=207113
Link: https://lore.kernel.org/lkml/20241006072542.66442-2-t.v.s10123@xxxxxxxxx/T/
Link: https://lore.kernel.org/lkml/20260825191333.34276-1-skunkolee@xxxxxxxxx/T/
Reviewed-by: Lasse Collin <lasse.collin@xxxxxxxxxxx>
Signed-off-by: Ivy Lopez <skunkolee@xxxxxxxxx>
---
lib/decompress_unxz.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/decompress_unxz.c b/lib/decompress_unxz.c
index 05d5cb490a44..9ccded9934c6 100644
--- a/lib/decompress_unxz.c
+++ b/lib/decompress_unxz.c
@@ -342,13 +342,13 @@ STATIC int INIT unxz(unsigned char *in, long in_size,
b.out_pos = 0;
}
} while (ret == XZ_OK);
+ }
- if (must_free_in)
- free(in);
+ if (must_free_in)
+ free(in);
- if (flush != NULL)
- free(b.out);
- }
+ if (flush != NULL)
+ free(b.out);
if (in_used != NULL)
*in_used += b.in_pos;
--
2.55.0