There is no need to allocate 2 * max_pending_size (which can be 256M) if
we're just extracting super block.

We only need to prepare BTRFS_SUPER_INFO_SIZE as buffer size.

Signed-off-by: Qu Wenruo <w...@suse.com>
---
 image/main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/image/main.c b/image/main.c
index d6e21ed68b87..7ca207de3c3a 100644
--- a/image/main.c
+++ b/image/main.c
@@ -1670,9 +1670,14 @@ static int fill_mdres_info(struct mdrestore_struct 
*mdres,
                return 0;
 
        if (mdres->compress_method == COMPRESS_ZLIB) {
-               size_t size = current_version->max_pending_size * 2;
+               /*
+                * We know this item is superblock, its should only be 4K.
+                * Don't need to waste memory following max_pending_size as it
+                * can be as large as 256M.
+                */
+               size_t size = BTRFS_SUPER_INFO_SIZE;
 
-               buffer = malloc(current_version->max_pending_size * 2);
+               buffer = malloc(size);
                if (!buffer)
                        return -ENOMEM;
                ret = uncompress(buffer, (unsigned long *)&size,
-- 
2.22.0

Reply via email to