From e23aa8174d6a1242d81491ce30f10a8d5f9acb10 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Fri, 4 Feb 2022 00:17:49 +0000 Subject: [PATCH] stat: make free_clat_prio_stats() safe against NULL The sfree() in free_clat_prio_stats() itself handles NULL, so the function already handles a struct thread_stat without any per priority stats. (Per priority stats are disabled on threads/thread_stats that we know will never be able to contain more than a single priority.) However, if malloc() in e.g. gen_mixed_ddir_stats_from_ts() or __show_run_stats() failed to allocate memory, free_clat_prio_stats() will be supplied a NULL pointer. Fix free_clat_prio_stats() to handle a NULL pointer gracefully. Fixes: 4ad856497c0b ("stat: add a new function to allocate a clat_prio_stat array") Signed-off-by: Niklas Cassel Link: https://lore.kernel.org/r/20220204001741.34419-1-Niklas.Cassel@wdc.com Signed-off-by: Jens Axboe --- stat.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stat.c b/stat.c index 0876222a..1764eebc 100644 --- a/stat.c +++ b/stat.c @@ -2041,6 +2041,9 @@ void free_clat_prio_stats(struct thread_stat *ts) { enum fio_ddir ddir; + if (!ts) + return; + for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { sfree(ts->clat_prio[ddir]); ts->clat_prio[ddir] = NULL; -- 2.25.1