Commit c7f86efb by Carlos Martín Nieto

zstream: grow based on used memory rather than allocated

When deflating data, we might need to grow the buffer. Currently we
add a guess on top of the currently-allocated buffer size.

When we re-use the buffer, it already has some memory allocated; adding
to that means that we always grow the buffer regardless of how much we
need to use.

Instead, increase on top of the currently-used size. This still leaves
us with the allocated size of the largest object we compress, but it's a
minor pain compared to unbounded growth.

This fixes #2285.
parent 4f9d5414
...@@ -134,7 +134,7 @@ int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len) ...@@ -134,7 +134,7 @@ int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len)
while (!git_zstream_done(&zs)) { while (!git_zstream_done(&zs)) {
size_t step = git_zstream_suggest_output_len(&zs), written; size_t step = git_zstream_suggest_output_len(&zs), written;
if ((error = git_buf_grow(out, out->asize + step)) < 0) if ((error = git_buf_grow(out, out->size + step)) < 0)
goto done; goto done;
written = out->asize - out->size; written = out->asize - out->size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment