From 1bc05e89aacf9e2fa00dc5645f05b4aad9ef9447 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 17 Jan 2020 20:42:27 -0800 Subject: [PATCH] stat: Fix a memory leak in add_ddir_status_json() This patch fixes the following Coverity complaint: CID 173000 (#1 of 1): Resource leak (RESOURCE_LEAK) 18. leaked_storage: Variable ovals going out of scope leaks the storage it points to. Signed-off-by: Bart Van Assche --- stat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stat.c b/stat.c index 0ee153a9..b5dad4fa 100644 --- a/stat.c +++ b/stat.c @@ -1309,6 +1309,8 @@ static void add_ddir_status_json(struct thread_stat *ts, json_object_add_value_int(percentile_object, buf, ovals[i]); } + free(ovals); + if (output_format & FIO_OUTPUT_JSON_PLUS) { clat_bins_object = json_create_object(); if (ts->clat_percentiles) @@ -1347,8 +1349,6 @@ static void add_ddir_status_json(struct thread_stat *ts, if (output_format & FIO_OUTPUT_JSON_PLUS && ts->lat_percentiles) json_object_add_value_object(tmp_object, "bins", clat_bins_object); - free(ovals); - if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { if (rs->agg[ddir]) { p_of_agg = mean * 100 / (double) (rs->agg[ddir] / 1024); -- 2.25.1