From 857b6e1ae692c68f4c0f333f18e8957b73e5a596 Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Thu, 24 Jul 2025 10:42:15 +0200 Subject: [PATCH] Check for null pointer dereference in umfPoolDestroy() Signed-off-by: Lukasz Dorau --- src/memory_pool.c | 5 +++++ test/poolFixtures.hpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/memory_pool.c b/src/memory_pool.c index 4b0173c73..a91d9df31 100644 --- a/src/memory_pool.c +++ b/src/memory_pool.c @@ -277,6 +277,11 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops, } umf_result_t umfPoolDestroy(umf_memory_pool_handle_t hPool) { + if (hPool == NULL) { + LOG_ERR("memory pool handle is NULL"); + return UMF_RESULT_ERROR_INVALID_ARGUMENT; + } + if (umf_ba_global_is_destroyed()) { return UMF_RESULT_ERROR_UNKNOWN; } diff --git a/test/poolFixtures.hpp b/test/poolFixtures.hpp index 8f15d513f..15c99e54f 100644 --- a/test/poolFixtures.hpp +++ b/test/poolFixtures.hpp @@ -122,6 +122,11 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfMemTest); GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfPoolTest); GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfMultiPoolTest); +TEST_P(umfPoolTest, destroyNullptr) { + auto ret = umfPoolDestroy(nullptr); + ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT); +} + TEST_P(umfPoolTest, allocFree) { static constexpr size_t allocSize = 64; auto *ptr = umfPoolMalloc(pool.get(), allocSize);