From 257283cc389a8f453cbf4ebd028af79e9b23258b Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 7 Aug 2018 15:52:11 +0300 Subject: [PATCH] Fixed unit library mutex usage. For the optimization purpose, function nxt_unit_remove_process() expects lib->mutex to be locked. The function then moves ports queue into temporary queue and releases mutex. In nxt_unit_done() there were two errors: mutex was not locked before nxt_unit_remove_process() call and mutex was not destroyed. It is hard to tell what was possible negative impact of this errors. Found by Coverity (CID 308517). --- src/nxt_unit.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index 2694de7d..b7ac9b61 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -2728,14 +2728,20 @@ nxt_unit_done(nxt_unit_ctx_t *ctx) } nxt_queue_loop; for ( ;; ) { + pthread_mutex_lock(&lib->mutex); + process = nxt_unit_process_pop_first(lib); if (process == NULL) { + pthread_mutex_unlock(&lib->mutex); + break; } nxt_unit_remove_process(ctx, process); } + pthread_mutex_destroy(&lib->mutex); + free(lib); }