stat: fix potential segfault for json output on network client
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index 2c218158b8cd61aa2780acb6d412e7a42b4bb5b4..2a65fed8fc2ebd61a8c4de3df97fff463fe3e23c 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1083,9 +1083,10 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
 
        /* ETA Info */
        je = get_jobs_eta(1, &size);
-       json_object_add_value_int(root, "eta", je->eta_sec);
-       json_object_add_value_int(root, "elapsed", je->elapsed_sec);
-
+       if (je) {
+               json_object_add_value_int(root, "eta", je->eta_sec);
+               json_object_add_value_int(root, "elapsed", je->elapsed_sec);
+       }
 
        add_ddir_status_json(ts, rs, DDIR_READ, root);
        add_ddir_status_json(ts, rs, DDIR_WRITE, root);
@@ -1627,15 +1628,14 @@ void __show_run_stats(void)
                show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL, &output[__FIO_OUTPUT_NORMAL]);
        }
 
-       for (i = 0; i < FIO_OUTPUT_NR; i++)
+       for (i = 0; i < FIO_OUTPUT_NR; i++) {
                buf_output_flush(&output[i]);
+               buf_output_free(&output[i]);
+       }
 
        log_info_flush();
        free(runstats);
        free(threadstats);
-
-       for (i = 0; i < FIO_OUTPUT_NR; i++)
-               buf_output_free(&output[i]);
 }
 
 void show_run_stats(void)