There are no needs to allocate more than one cluster, as we set
avail_out for deflate to one cluster.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
Hi all!
Please, can anybody say me what I'm missing?
I've looked through deflate documentation at
http://www.zlib.net/manual.html, and I didn't find anything about
allocating more memory for out buffer than specified in avail_out
field.. What is this magic formula?
========
All uses of out_buf in the function:
uint8_t *out_buf;
...
out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
...
strm.avail_out = s->cluster_size;
strm.next_out = out_buf;
ret = deflate(&strm, Z_FINISH);
...
out_len = strm.next_out - out_buf;
...
ret = bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len);
...
g_free(out_buf);
block/qcow.c | 2 +-
block/qcow2.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/qcow.c b/block/qcow.c
index ac849bd..d8826f3 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -983,7 +983,7 @@ static int qcow_write_compressed(BlockDriverState *bs,
int64_t sector_num,
return ret;
}
- out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
+ out_buf = g_malloc(s->cluster_size);
/* best compression, small window, no zlib header */
memset(&strm, 0, sizeof(strm));
diff --git a/block/qcow2.c b/block/qcow2.c
index a5ea19b..b1c90ae 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2612,7 +2612,7 @@ static int qcow2_write_compressed(BlockDriverState *bs,
int64_t sector_num,
return ret;
}
- out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
+ out_buf = g_malloc(s->cluster_size);
/* best compression, small window, no zlib header */
memset(&strm, 0, sizeof(strm));