Can you please test the attached patch if it fixes the memory leakage?

> This is also the case why not all CPU cores are used  during the run
> of mksquashfs.

This is a known bug/feature, as it removes one thread.
mksquashfs only scales the frad_thrd, deflator & removed frag_deflator
thread by the number of cpus.
https://lunarius.fe80.eu/blog/mksquash-dot-graph.html
From c0f336924df833f22be40c34faf2863f39201de3 Mon Sep 17 00:00:00 2001
From: Alexander Couzens <lyn...@fe80.eu>
Date: Mon, 25 Mar 2019 04:55:00 +0100
Subject: [PATCH] mksquashfs: fix compressor initialisation in frag_deflator

Since 97537a036043 the compressor will be initialized on every call
introducing a memory leak on every frag_deflator called.
Use a static and only initialize the stream only once, will leak only
once, as all comp_init() may leak.

Fixes: 97537a036043 ("flag_deflator: initialize the compressor()")
---
 squashfs-tools/mksquashfs.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
index 935d96013a73..21c7e85e009a 100644
--- a/squashfs-tools/mksquashfs.c
+++ b/squashfs-tools/mksquashfs.c
@@ -2409,12 +2409,18 @@ void frag_deflator(struct file_buffer *file_buffer)
 	int res, c_byte, compressed_size;
 	struct file_buffer *write_buffer;
 
-	res = compressor_init(comp, &stream, block_size, 1);
-	if(res)
-		BAD_ERROR("frag_deflator:: compressor_init failed\n");
+	static int frag_deflator_comp_init = FALSE;
+	static void *frag_stream = NULL;
+
+	if (frag_deflator_comp_init == FALSE) {
+		frag_deflator_comp_init = TRUE;
+		res = compressor_init(comp, &frag_stream, block_size, 1);
+		if(res)
+			BAD_ERROR("frag_deflator:: compressor_init failed\n");
+	}
 
 	write_buffer = cache_get(fwriter_buffer, file_buffer->block);
-	c_byte = mangle2(stream, write_buffer->data, file_buffer->data,
+	c_byte = mangle2(frag_stream, write_buffer->data, file_buffer->data,
 			 file_buffer->size, block_size, noF, 1);
 	compressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
 	write_buffer->size = compressed_size;
-- 
2.21.0

Attachment: pgpVbCI14r7ly.pgp
Description: OpenPGP digital signature

Reply via email to