Skip to content

Ignore error of os_munmap() when size equals 0 #102

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
3 changes: 2 additions & 1 deletion src/provider/provider_os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ static umf_result_t os_free(void *provider, void *ptr, size_t size) {

errno = 0;
int ret = os_munmap(ptr, size);
if (ret) {
// ignore error when size == 0
if (ret && (size > 0)) {
os_store_last_native_error(UMF_OS_RESULT_ERROR_FREE_FAILED, errno);
if (os_config->traces) {
perror("memory deallocation failed");
Expand Down
15 changes: 13 additions & 2 deletions test/provider_os_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,22 @@ TEST_P(umfProviderTest, get_name) {
ASSERT_STREQ(name, "OS");
}

TEST_P(umfProviderTest, free_size_0_ptr_not_null) {
umf_result_t umf_result =
umfMemoryProviderFree(provider.get(), INVALID_PTR, 0);
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
}

// other negative tests

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

TEST_P(umfProviderTest, free_INVALID_POINTER_SIZE_GT_0) {
umf_result_t umf_result =
umfMemoryProviderFree(provider.get(), INVALID_PTR, 0);
umfMemoryProviderFree(provider.get(), INVALID_PTR, page_plus_64);
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC);

verify_last_native_error(provider.get(), UMF_OS_RESULT_ERROR_FREE_FAILED);
Expand Down