Skip to content

Fix: os_free(NULL) should return UMF_RESULT_SUCCESS #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/provider/provider_os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,14 @@ static umf_result_t os_alloc(void *provider, size_t size, size_t alignment,
}

static umf_result_t os_free(void *provider, void *ptr, size_t size) {
if (provider == NULL || ptr == NULL) {
if (provider == NULL) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

if (ptr == NULL) {
return UMF_RESULT_SUCCESS;
}

os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;

if (os_provider->fd > 0) {
Expand Down
6 changes: 3 additions & 3 deletions test/provider_os_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ TEST_P(umfProviderTest, free_size_0_ptr_not_null) {
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
}

// other negative tests

TEST_P(umfProviderTest, free_NULL) {
umf_result_t umf_result = umfMemoryProviderFree(provider.get(), nullptr, 0);
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
}

// other negative tests

TEST_P(umfProviderTest, free_INVALID_POINTER_SIZE_GT_0) {
umf_result_t umf_result =
umfMemoryProviderFree(provider.get(), INVALID_PTR, page_plus_64);
Expand Down