Shrink critical section in iperf_err().

This is similar to what was done for iperf_errexit() in a previous commit.
diff --git a/src/iperf_error.c b/src/iperf_error.c
index 12ab3eb..0fedf31 100644
--- a/src/iperf_error.c
+++ b/src/iperf_error.c
@@ -47,10 +47,6 @@
     struct tm *ltm = NULL;
     char *ct = NULL;
 
-    if (pthread_mutex_lock(&(test->print_mutex)) != 0) {
-        perror("iperf_err: pthread_mutex_lock");
-    }
-
     /* Timestamp if requested */
     if (test != NULL && test->timestamps) {
 	time(&now);
@@ -64,6 +60,10 @@
     if (test != NULL && test->json_output && test->json_top != NULL)
 	cJSON_AddStringToObject(test->json_top, "error", str);
     else {
+        if (pthread_mutex_lock(&(test->print_mutex)) != 0) {
+            perror("iperf_err: pthread_mutex_lock");
+        }
+
 	if (test && test->outfile && test->outfile != stdout) {
 	    if (ct) {
 		fprintf(test->outfile, "%s", ct);
@@ -76,12 +76,13 @@
 	    }
 	    fprintf(stderr, "iperf3: %s\n", str);
 	}
+
+        if (pthread_mutex_unlock(&(test->print_mutex)) != 0) {
+            perror("iperf_err: pthread_mutex_unlock");
+        }
+
     }
     va_end(argp);
-
-    if (pthread_mutex_unlock(&(test->print_mutex)) != 0) {
-        perror("iperf_err: pthread_mutex_unlock");
-    }
 }
 
 /* Do a printf to stderr or log file as appropriate, then exit. */