]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: image: free the buffer if output allocation failed
authorQu Wenruo <wqu@suse.com>
Sun, 25 Oct 2026 08:41:39 +0000 (19:11 +1030)
committerQu Wenruo <wqu@suse.com>
Mon, 26 Oct 2026 21:38:10 +0000 (08:08 +1030)
Inside dump_worker(), if the compression output buffer allocation
failed, since async->buffer is reused, no one can reach the old original
buffer.

This leads to leaked memory on the error path. Release the original
buffer in that case.

Assisted-by: LLM (exposing the bug)
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
image/image-create.c

index 75f4505200597a39dcb147a2229f16da855b6363..97348f37acaa3c09a76056f14151eeafcc0793f9 100644 (file)
@@ -68,6 +68,7 @@ static void *dump_worker(void *data)
                        async->bufsize = compressBound(async->size);
                        async->buffer = malloc(async->bufsize);
                        if (!async->buffer) {
+                               free(orig);
                                error_mem("async buffer");
                                pthread_mutex_lock(&md->mutex);
                                if (!md->error)