From 01888d2e2a133e044e5b3bf6fe2712b4c4b7d510 Mon Sep 17 00:00:00 2001 From: Martin Ottens Date: Wed, 11 Dec 2024 17:18:14 +0100 Subject: [PATCH] Fix Segfault in iperf_err(exit) --- src/iperf_error.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/iperf_error.c b/src/iperf_error.c index e06723ba6..da24f895a 100644 --- a/src/iperf_error.c +++ b/src/iperf_error.c @@ -60,6 +60,7 @@ iperf_err(struct iperf_test *test, const char *format, ...) if (test != NULL && test->json_output && test->json_top != NULL) cJSON_AddStringToObject(test->json_top, "error", str); else { + if (test != NULL) if (pthread_mutex_lock(&(test->print_mutex)) != 0) { perror("iperf_err: pthread_mutex_lock"); } @@ -77,6 +78,7 @@ iperf_err(struct iperf_test *test, const char *format, ...) fprintf(stderr, "iperf3: %s\n", str); } + if (test != NULL) if (pthread_mutex_unlock(&(test->print_mutex)) != 0) { perror("iperf_err: pthread_mutex_unlock"); } @@ -111,6 +113,7 @@ iperf_errexit(struct iperf_test *test, const char *format, ...) } iperf_json_finish(test); } else { + if (test != NULL) if (pthread_mutex_lock(&(test->print_mutex)) != 0) { perror("iperf_errexit: pthread_mutex_lock"); } @@ -128,6 +131,7 @@ iperf_errexit(struct iperf_test *test, const char *format, ...) fprintf(stderr, "iperf3: %s\n", str); } + if (test != NULL) if (pthread_mutex_unlock(&(test->print_mutex)) != 0) { perror("iperf_errexit: pthread_mutex_unlock"); }