Skip to content

Commit

Permalink
Fix Segfault in iperf_err(exit)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-ottens committed Dec 11, 2024
1 parent d595ee6 commit 01888d2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/iperf_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down

0 comments on commit 01888d2

Please sign in to comment.