Skip to content

Commit 857b6e1

Browse files
committed
Check for null pointer dereference in umfPoolDestroy()
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent af263c6 commit 857b6e1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/memory_pool.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
277277
}
278278

279279
umf_result_t umfPoolDestroy(umf_memory_pool_handle_t hPool) {
280+
if (hPool == NULL) {
281+
LOG_ERR("memory pool handle is NULL");
282+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
283+
}
284+
280285
if (umf_ba_global_is_destroyed()) {
281286
return UMF_RESULT_ERROR_UNKNOWN;
282287
}

test/poolFixtures.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfMemTest);
122122
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfPoolTest);
123123
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(umfMultiPoolTest);
124124

125+
TEST_P(umfPoolTest, destroyNullptr) {
126+
auto ret = umfPoolDestroy(nullptr);
127+
ASSERT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
128+
}
129+
125130
TEST_P(umfPoolTest, allocFree) {
126131
static constexpr size_t allocSize = 64;
127132
auto *ptr = umfPoolMalloc(pool.get(), allocSize);

0 commit comments

Comments
 (0)