From 2ec43d12615b75dc7c19776c85929a3539bb0507 Mon Sep 17 00:00:00 2001 From: David Bar-On Date: Tue, 18 May 2021 14:44:47 +0300 Subject: [PATCH] Fix issue #1143 - make sure terminating error message is inside the JSON output --- src/iperf_client_api.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index df7be5298..e7031b33b 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -651,9 +651,13 @@ iperf_run_client(struct iperf_test * test) return 0; cleanup_and_fail: + iperf_errexit(test, "error - %s", iperf_strerror(i_errno)); iperf_client_end(test); - if (test->json_output) - iperf_json_finish(test); + if (test->json_output) { + if (iperf_json_finish(test) < 0) + return -1; // It is o.k. that error will be logged later outside the JSON output since its creation failed + } iflush(test); - return -1; + return 0; // Return 0 and not -1 since all terminating function were done here. + // Also prevents error message logging outside the already closed JSON output. }