From 0932de54bc0dbc6d29008b9e6087b88721ca8bb0 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 26 Aug 2019 18:19:29 -0700 Subject: [PATCH] [dictBuilder] Fix deadlock in *COVER error case The COVER and FASTCOVER dictionary builders can deadlock when dictionary construction errors, likely because there are too few samples, or too few distinct dmers. The deadlock only occurs when there are errors. Fixes #1746. --- lib/dictBuilder/cover.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/dictBuilder/cover.c b/lib/dictBuilder/cover.c index 62199675..4721205d 100644 --- a/lib/dictBuilder/cover.c +++ b/lib/dictBuilder/cover.c @@ -919,13 +919,12 @@ void COVER_best_finish(COVER_best_t *best, ZDICT_cover_params_t parameters, } } /* Save the dictionary, parameters, and size */ - if (!dict) { - return; + if (dict) { + memcpy(best->dict, dict, dictSize); + best->dictSize = dictSize; + best->parameters = parameters; + best->compressedSize = compressedSize; } - memcpy(best->dict, dict, dictSize); - best->dictSize = dictSize; - best->parameters = parameters; - best->compressedSize = compressedSize; } if (liveJobs == 0) { ZSTD_pthread_cond_broadcast(&best->cond);