Skip to content

Commit

Permalink
Fix #1631 - prevent server termination with JSON and remove redundant…
Browse files Browse the repository at this point in the history
… code with error
  • Loading branch information
davidBar-On committed Mar 27, 2024
1 parent b5eb3a4 commit 0731b5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
11 changes: 1 addition & 10 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4889,16 +4889,7 @@ iperf_json_finish(struct iperf_test *test)
cJSON_Delete(test->json_top);
test->json_top = NULL;
}
// Get ASCII rendering of JSON structure. Then make our
// own copy of it and return the storage that cJSON allocated
// on our behalf. We keep our own copy around.
char *str = cJSON_Print(test->json_top);
if (str == NULL)
return -1;
test->json_output_string = strdup(str);
cJSON_free(str);
if (test->json_output_string == NULL)
return -1;

if (test->json_stream) {
cJSON *error = cJSON_GetObjectItem(test->json_top, "error");
if (error) {
Expand Down
15 changes: 8 additions & 7 deletions src/iperf_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ iperf_errexit(struct iperf_test *test, const char *format, ...)
struct tm *ltm = NULL;
char *ct = NULL;

if (pthread_mutex_lock(&(test->print_mutex)) != 0) {
perror("iperf_errexit: pthread_mutex_lock");
}

/* Timestamp if requested */
if (test != NULL && test->timestamps) {
time(&now);
Expand All @@ -113,7 +109,11 @@ iperf_errexit(struct iperf_test *test, const char *format, ...)
cJSON_AddStringToObject(test->json_top, "error", str);
}
iperf_json_finish(test);
} else
} else {
if (pthread_mutex_unlock(&(test->print_mutex)) != 0) {
perror("iperf_errexit: pthread_mutex_unlock");
}

if (test && test->outfile && test->outfile != stdout) {
if (ct) {
fprintf(test->outfile, "%s", ct);
Expand All @@ -127,8 +127,9 @@ iperf_errexit(struct iperf_test *test, const char *format, ...)
fprintf(stderr, "iperf3: %s\n", str);
}

if (pthread_mutex_unlock(&(test->print_mutex)) != 0) {
perror("iperf_errexit: pthread_mutex_unlock");
if (pthread_mutex_lock(&(test->print_mutex)) != 0) {
perror("iperf_errexit: pthread_mutex_lock");
}
}

va_end(argp);
Expand Down

0 comments on commit 0731b5e

Please sign in to comment.