From 1a1723834bacbbd9b9b18ffa67da4e6c123c7b62 Mon Sep 17 00:00:00 2001 From: Andrew Reading Date: Sat, 23 Feb 2019 21:01:24 -0800 Subject: [PATCH] Fix segfault from thread race condition during decompression. This fixes an issue where the main thread would not wait for all worker threads to fully join before attempting to process their result buffers: new_thread was true up until to the final N-1 calls, at which point the input stream will have ended and new_thread would be false, then bypassing the pthread_join()s. The new_thread condition isn't actually necessary at all, so it has been entirely removed. --- stream.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stream.c b/stream.c index 0dc68be..357f921 100644 --- a/stream.c +++ b/stream.c @@ -1567,14 +1567,12 @@ static int fill_buffer(rzip_control *control, struct stream_info *sinfo, struct i64 u_len, c_len, last_head, padded_len, header_length, max_len; uchar enc_head[25 + SALT_LEN], blocksalt[SALT_LEN]; stream_thread_struct *st; - bool new_thread = false; uchar c_type, *s_buf; dealloc(s->buf); if (s->eos) goto out; fill_another: - new_thread = true; if (unlikely(ucthread[s->uthread_no].busy)) failure_return(("Trying to start a busy thread, this shouldn't happen!\n"), -1); @@ -1704,7 +1702,7 @@ out: unlock_mutex(control, &output_lock); /* join_pthread here will make it wait till the data is ready */ - if (unlikely(new_thread && !join_pthread(control, threads[s->unext_thread], NULL))) + if (unlikely(!join_pthread(control, threads[s->unext_thread], NULL))) return -1; ucthread[s->unext_thread].busy = 0;