From 3f23832dd1cdc51239738464d8b6f243485c9373 Mon Sep 17 00:00:00 2001 From: kirill reshke Date: Thu, 22 Oct 2020 16:01:18 +0500 Subject: [PATCH] fix a bunch of coverity issues (#221) Co-authored-by: reshke --- sources/client.h | 4 ++-- sources/config.c | 2 +- sources/counter.c | 6 +++++- sources/err_logger.c | 5 ++++- sources/tdigest.c | 2 +- sources/watchdog.c | 3 ++- sources/worker_pool.h | 13 ++++--------- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/sources/client.h b/sources/client.h index 64348752..79b8e89b 100644 --- a/sources/client.h +++ b/sources/client.h @@ -101,11 +101,11 @@ od_client_free(od_client_t *client) free(client); } -static inline void +static inline od_retcode_t od_client_notify_read(od_client_t *client) { uint64_t value; - machine_read_raw(client->notify_io, &value, sizeof(value)); + return machine_read_raw(client->notify_io, &value, sizeof(value)); } static inline void diff --git a/sources/config.c b/sources/config.c index 844f3855..3f9c2a6d 100644 --- a/sources/config.c +++ b/sources/config.c @@ -212,7 +212,7 @@ od_config_validate(od_config_t *config, od_logger_t *logger) } if (config->enable_online_restart_feature && !config->bindwith_reuseport) { - od_dbg_printf_on_dvl_lvl(1, "validation error detected\n", ""); + od_dbg_printf_on_dvl_lvl(1, "validation error detected %s\n", ""); od_error(logger, "config", NULL, diff --git a/sources/counter.c b/sources/counter.c index 4557a0d6..2377a9ef 100644 --- a/sources/counter.c +++ b/sources/counter.c @@ -55,14 +55,18 @@ od_counter_create(size_t sz) } t->bucket_mutex = malloc(sizeof(pthread_mutex_t) * sz); if (t->bucket_mutex == NULL) { + free(t); return NULL; } t->size = sz; for (size_t i = 0; i < t->size; ++i) { t->buckets[i] = od_counter_llist_create(); - if (t->buckets[i] == NULL) + if (t->buckets[i] == NULL) { + free(t->bucket_mutex); + free(t); return NULL; + } const int res = pthread_mutex_init(&t->bucket_mutex[i], NULL); if (res) { return NULL; diff --git a/sources/err_logger.c b/sources/err_logger.c index 8c8308dd..61c15b4b 100644 --- a/sources/err_logger.c +++ b/sources/err_logger.c @@ -17,8 +17,11 @@ od_err_logger_create(size_t intervals_count) for (size_t i = 0; i < intervals_count; ++i) { err_logger->interval_counters[i] = od_counter_create_default(); - if (err_logger->interval_counters[i] == NULL) + if (err_logger->interval_counters[i] == NULL) { + free(err_logger->interval_counters); + free(err_logger); return NULL; + } } pthread_mutex_init(&err_logger->lock, NULL); diff --git a/sources/tdigest.c b/sources/tdigest.c index d9a54ad0..4c7c11df 100644 --- a/sources/tdigest.c +++ b/sources/tdigest.c @@ -373,4 +373,4 @@ merge(td_histogram_t *h) h->merged_count = total_count; h->unmerged_nodes = 0; h->unmerged_count = 0; -} \ No newline at end of file +} diff --git a/sources/watchdog.c b/sources/watchdog.c index 750cf42a..09692fdf 100644 --- a/sources/watchdog.c +++ b/sources/watchdog.c @@ -60,6 +60,7 @@ od_watchdog_worker(void *arg) } else { kill(instance->pid.pid, SIGKILL); } + close(fd_ctrl); return; } @@ -96,7 +97,7 @@ od_watchdog_worker(void *arg) } flock(fd_exec, LOCK_UN | LOCK_NB); - /* request out own process to shutdown */ + /* request our own process to shutdown */ kill(instance->pid.pid, OD_SIG_GRACEFUL_SHUTDOWN); return; } diff --git a/sources/worker_pool.h b/sources/worker_pool.h index 134a3407..edf0a75a 100644 --- a/sources/worker_pool.h +++ b/sources/worker_pool.h @@ -1,6 +1,7 @@ #ifndef ODYSSEY_WORKER_POOL_H #define ODYSSEY_WORKER_POOL_H +#include /* * Odyssey. * @@ -67,15 +68,7 @@ od_worker_pool_wait(od_worker_pool_t *pool) if (!is_shared) return; - // In fact we cannot wait anything here - machines may be in epoll waiting - // No new TLS handshakes should be initiated, so, just wait a bit. machine_sleep(1); - /* - for (int i = 0; i < pool->count; i++) { - od_worker_t *worker = &pool->pool[i]; - machine_wait(worker->machine); - } - */ } static inline void @@ -93,7 +86,9 @@ od_worker_pool_wait_gracefully_shutdown(od_worker_pool_t *pool) // machine_sleep(1); for (int i = 0; i < pool->count; i++) { od_worker_t *worker = &pool->pool[i]; - machine_wait(worker->machine); + int rc = machine_wait(worker->machine); + if (rc != MM_OK_RETCODE) + return; } }