summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_fullscrape.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/ot_fullscrape.c b/ot_fullscrape.c
index 8f8ee9d..d299ed9 100644
--- a/ot_fullscrape.c
+++ b/ot_fullscrape.c
@@ -285,16 +285,10 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) {
285 return mutex_bucket_unlock(bucket, 0); 285 return mutex_bucket_unlock(bucket, 0);
286 } 286 }
287 287
288 { 288 /* Check if there's a last batch of data in the zlib buffer */
289 unsigned int pending; 289 if (!strm.avail_out) {
290 int bits;
291 deflatePending(&strm, &pending, &bits);
292 pending += (bits ? 1 : 0);
293
294 if (pending) {
295 /* Allocate a fresh output buffer */ 290 /* Allocate a fresh output buffer */
296 iovector.iov_base = malloc(pending); 291 iovector.iov_base = malloc(OT_SCRAPE_CHUNK_SIZE);
297 iovector.iov_len = pending;
298 292
299 if (!iovector.iov_base) { 293 if (!iovector.iov_base) {
300 fprintf(stderr, "Problem with iovec_fix_increase_or_free\n"); 294 fprintf(stderr, "Problem with iovec_fix_increase_or_free\n");
@@ -302,13 +296,14 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) {
302 return mutex_bucket_unlock(bucket, 0); 296 return mutex_bucket_unlock(bucket, 0);
303 } 297 }
304 strm.next_out = iovector.iov_base; 298 strm.next_out = iovector.iov_base;
305 strm.avail_out = pending; 299 strm.avail_out = OT_SCRAPE_CHUNK_SIZE;
306 if (deflate(&strm, Z_FINISH) < Z_OK) 300 if (deflate(&strm, Z_FINISH) < Z_OK)
307 fprintf(stderr, "deflate() failed while in fullscrape_make()'s endgame.\n"); 301 fprintf(stderr, "deflate() failed while in fullscrape_make()'s endgame.\n");
308 302
309 if (mutex_workqueue_pushchunked(taskid, &iovector)) 303 /* Only pass the new buffer if there actually was some data left in the buffer */
304 iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base;
305 if (!iovector.iov_len || mutex_workqueue_pushchunked(taskid, &iovector))
310 free(iovector.iov_base); 306 free(iovector.iov_base);
311 }
312 } 307 }
313 308
314 deflateEnd(&strm); 309 deflateEnd(&strm);