stat: make free_clat_prio_stats() safe against NULL
authorNiklas Cassel <niklas.cassel@wdc.com>
Fri, 4 Feb 2022 00:17:49 +0000 (00:17 +0000)
committerJens Axboe <axboe@kernel.dk>
Fri, 4 Feb 2022 00:18:58 +0000 (17:18 -0700)
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 <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20220204001741.34419-1-Niklas.Cassel@wdc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
stat.c

diff --git a/stat.c b/stat.c
index 0876222a1b6be28d0f5fd7ce6b278e6f90c099ff..1764eebc697ab52bc467a4dc922b93e01f5422e9 100644 (file)
--- 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;