From 89da13e73139d4bbaa5eaa8e83a8a9e9ff30e2c8 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Tue, 21 Nov 2023 21:58:36 +0100 Subject: [PATCH] mpi: remove NULL checks before frees As Coverity points out, paths reaching these NULL checks will have already dereferenced the pointers. So use the same condition as for the allocation. --- mpi/libmpiwrap.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mpi/libmpiwrap.c b/mpi/libmpiwrap.c index df0a1ae9df..24221f8108 100644 --- a/mpi/libmpiwrap.c +++ b/mpi/libmpiwrap.c @@ -869,9 +869,15 @@ void walk_type ( void(*f)(void*,long), char* base, MPI_Datatype ty ) } /* normal exit */ - if (ints) free(ints); - if (addrs) free(addrs); - if (dtys) free(dtys); + if (n_ints > 0) { + free(ints); + } + if (n_addrs > 0) { + free(addrs); + } + if (n_dtys) { + free(dtys); + } return; unhandled: -- 2.47.2