[PATCH v2] lib: decompress_unxz: Make it obvious that there is no memory leak

Ivy Lopez posted 1 patch 3 weeks, 4 days ago
lib/decompress_unxz.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
[PATCH v2] lib: decompress_unxz: Make it obvious that there is no memory leak
Posted by Ivy Lopez 3 weeks, 4 days ago
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@gmail.com/T/
Link: https://lore.kernel.org/lkml/20260825191333.34276-1-skunkolee@gmail.com/T/
Reviewed-by: Lasse Collin <lasse.collin@tukaani.org>
Signed-off-by: Ivy Lopez <skunkolee@gmail.com>
---
 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