Skip to content

Commit 1e60925

Browse files
ldorauKFilipek
authored andcommitted
Fix: os_free(NULL) should return UMF_RESULT_SUCCESS
Fix: os_free(NULL) should return UMF_RESULT_SUCCESS instead of UMF_RESULT_ERROR_INVALID_ARGUMENT. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 3298399 commit 1e60925

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/provider/provider_os_memory.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,14 @@ static umf_result_t os_alloc(void *provider, size_t size, size_t alignment,
560560
}
561561

562562
static umf_result_t os_free(void *provider, void *ptr, size_t size) {
563-
if (provider == NULL || ptr == NULL) {
563+
if (provider == NULL) {
564564
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
565565
}
566566

567+
if (ptr == NULL) {
568+
return UMF_RESULT_SUCCESS;
569+
}
570+
567571
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
568572

569573
if (os_provider->fd > 0) {

test/provider_os_memory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ TEST_P(umfProviderTest, free_size_0_ptr_not_null) {
268268
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
269269
}
270270

271-
// other negative tests
272-
273271
TEST_P(umfProviderTest, free_NULL) {
274272
umf_result_t umf_result = umfMemoryProviderFree(provider.get(), nullptr, 0);
275-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
273+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
276274
}
277275

276+
// other negative tests
277+
278278
TEST_P(umfProviderTest, free_INVALID_POINTER_SIZE_GT_0) {
279279
umf_result_t umf_result =
280280
umfMemoryProviderFree(provider.get(), INVALID_PTR, page_plus_64);

0 commit comments

Comments
 (0)