summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_unit.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2018-08-07 15:52:11 +0300
committerMax Romanov <max.romanov@nginx.com>2018-08-07 15:52:11 +0300
commit257283cc389a8f453cbf4ebd028af79e9b23258b (patch)
treec466cca23d07ab0569c20e6faea1735d5345d9ee /src/nxt_unit.c
parent09268676ef9f80291c554431b15495afd63177af (diff)
downloadunit-257283cc389a8f453cbf4ebd028af79e9b23258b.tar.gz
unit-257283cc389a8f453cbf4ebd028af79e9b23258b.tar.bz2
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).
Diffstat (limited to 'src/nxt_unit.c')
-rw-r--r--src/nxt_unit.c6
1 files changed, 6 insertions, 0 deletions
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);
}