150
if (block_writer_type(w) == BLOCK_TYPE_LOG) {
151
int block_header_skip = 4 + w->header_off;
152
uLongf src_len = w->next - block_header_skip, compressed_len;
153
- unsigned char *compressed;
153
int ret;
154
155
ret = deflateReset(w->zstream);
162
* is guaranteed to return `Z_STREAM_END`.
163
*/
164
compressed_len = deflateBound(w->zstream, src_len);
166
- REFTABLE_ALLOC_ARRAY(compressed, compressed_len);
165
+ REFTABLE_ALLOC_GROW(w->compressed, compressed_len, w->compressed_cap);
166
168
- w->zstream->next_out = compressed;
167
+ w->zstream->next_out = w->compressed;
168
w->zstream->avail_out = compressed_len;
169
w->zstream->next_in = w->buf + block_header_skip;
170
w->zstream->avail_in = src_len;
176
* guaranteed to succeed according to the zlib documentation.
177
*/
178
ret = deflate(w->zstream, Z_FINISH);
180
- if (ret != Z_STREAM_END) {
181
- reftable_free(compressed);
179
+ if (ret != Z_STREAM_END)
180
return REFTABLE_ZLIB_ERROR;
183
- }
181
182
/*
183
* Overwrite the uncompressed data we have already written and
184
* adjust the `next` pointer to point right after the
185
* compressed data.
186
*/
190
- memcpy(w->buf + block_header_skip, compressed,
187
+ memcpy(w->buf + block_header_skip, w->compressed,
188
w->zstream->total_out);
189
w->next = w->zstream->total_out + block_header_skip;
193
-
194
- reftable_free(compressed);
190
}
191
192
return w->next;
445
deflateEnd(bw->zstream);
446
FREE_AND_NULL(bw->zstream);
447
FREE_AND_NULL(bw->restarts);
448
+ FREE_AND_NULL(bw->compressed);
449
strbuf_release(&bw->last_key);
450
/* the block is not owned. */
451
}