From ed24e32c0fcccbf68cbb8ad853f99d171842f270 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 17 Jan 2020 21:00:01 -0800 Subject: [PATCH] stat: Fix another memory leak in add_ddir_status_json() Only compute the percentile_object and clat_bins_object data structures if these will be stored inside another JSON object. Signed-off-by: Bart Van Assche --- stat.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/stat.c b/stat.c index b5dad4fa..4d3b728c 100644 --- a/stat.c +++ b/stat.c @@ -1206,7 +1206,8 @@ static void add_ddir_status_json(struct thread_stat *ts, double mean, dev, iops; unsigned int len; int i; - struct json_object *dir_object, *tmp_object, *percentile_object, *clat_bins_object = NULL; + struct json_object *dir_object, *tmp_object, *percentile_object = NULL, + *clat_bins_object = NULL; char buf[120]; double p_of_agg = 100.0; @@ -1301,20 +1302,23 @@ static void add_ddir_status_json(struct thread_stat *ts, } else len = 0; - percentile_object = json_create_object(); - if (ts->clat_percentiles) + if (ts->clat_percentiles) { + percentile_object = json_create_object(); json_object_add_value_object(tmp_object, "percentile", percentile_object); - for (i = 0; i < len; i++) { - snprintf(buf, sizeof(buf), "%f", ts->percentile_list[i].u.f); - json_object_add_value_int(percentile_object, buf, ovals[i]); + for (i = 0; i < len; i++) { + snprintf(buf, sizeof(buf), "%f", + ts->percentile_list[i].u.f); + json_object_add_value_int(percentile_object, buf, + ovals[i]); + } } free(ovals); - if (output_format & FIO_OUTPUT_JSON_PLUS) { + if (output_format & FIO_OUTPUT_JSON_PLUS && ts->clat_percentiles) { clat_bins_object = json_create_object(); - if (ts->clat_percentiles) - json_object_add_value_object(tmp_object, "bins", clat_bins_object); + json_object_add_value_object(tmp_object, "bins", + clat_bins_object); for(i = 0; i < FIO_IO_U_PLAT_NR; i++) { if (ddir_rw(ddir)) { -- 2.25.1