Handle helper_thread_create() failures properly
authorBart Van Assche <bvanassche@acm.org>
Fri, 3 Jan 2020 21:21:53 +0000 (13:21 -0800)
committerBart Van Assche <bvanassche@acm.org>
Sat, 4 Jan 2020 05:46:17 +0000 (21:46 -0800)
Report helper_thread_create() failures. Make sure that no crash occurs
if helper_thread_create() fails.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
backend.c
helper_thread.c

index d0d691b39e5ed86ce8e29fa22610d235238dcf0b..0d1f473442e368cd82443ae0352dba5878a2b072 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2495,7 +2495,8 @@ int fio_backend(struct sk_out *sk_out)
 
        set_genesis_time();
        stat_init();
-       helper_thread_create(startup_sem, sk_out);
+       if (helper_thread_create(startup_sem, sk_out))
+               log_err("fio: failed to create helper thread\n");
 
        cgroup_list = smalloc(sizeof(*cgroup_list));
        if (cgroup_list)
index eba2898a24b6cf22bb4ad2f58e584f8765f78f68..51e8f06fa3ae1353b884ae6f8a6434bccb6372ee 100644 (file)
@@ -23,6 +23,9 @@ static struct helper_data {
 
 void helper_thread_destroy(void)
 {
+       if (!helper_data)
+               return;
+
        pthread_cond_destroy(&helper_data->cond);
        pthread_mutex_destroy(&helper_data->lock);
        sfree(helper_data);
@@ -66,6 +69,9 @@ void helper_thread_exit(void)
 {
        void *ret;
 
+       if (!helper_data)
+               return;
+
        pthread_mutex_lock(&helper_data->lock);
        helper_data->exit = 1;
        pthread_cond_signal(&helper_data->cond);