Skip to content
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

[umf] fix erors reported by ASAN #749

Merged
merged 1 commit into from
Jul 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum umf_result_t umfPoolCreate(const struct umf_memory_pool_ops_t *ops,
return UMF_RESULT_SUCCESS;

err_pool_init:
free(pool->providers);
err_providers_alloc:
free(pool);

Expand All @@ -64,6 +65,7 @@ enum umf_result_t umfPoolCreate(const struct umf_memory_pool_ops_t *ops,

void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
hPool->ops.finalize(hPool->pool_priv);
free(hPool->providers);
free(hPool);
}

Expand Down
13 changes: 7 additions & 6 deletions test/unified_malloc_framework/common/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,43 @@ auto wrapPoolUnique(umf_memory_pool_handle_t hPool) {
}

bool isReallocSupported(umf_memory_pool_handle_t hPool) {
static constexpr size_t allocSize = 1;
static constexpr size_t allocSize = 8;
bool supported;
auto *ptr = umfPoolMalloc(hPool, allocSize);
auto *new_ptr = umfPoolRealloc(hPool, ptr, allocSize * 2);

if (new_ptr) {
supported = true;
umfPoolFree(hPool, new_ptr);
} else if (umfPoolGetLastAllocationError(hPool) ==
UMF_RESULT_ERROR_NOT_SUPPORTED) {
umfPoolFree(hPool, ptr);
supported = false;
} else {
umfPoolFree(hPool, new_ptr);
throw std::runtime_error("realloc failed with unexpected error");
}

umfPoolFree(hPool, new_ptr);

return supported;
}

bool isCallocSupported(umf_memory_pool_handle_t hPool) {
static constexpr size_t num = 1;
static constexpr size_t num = 8;
static constexpr size_t size = sizeof(int);
bool supported;
auto *ptr = umfPoolCalloc(hPool, num, size);

if (ptr) {
supported = true;
umfPoolFree(hPool, ptr);
} else if (umfPoolGetLastAllocationError(hPool) ==
UMF_RESULT_ERROR_NOT_SUPPORTED) {
supported = false;
} else {
umfPoolFree(hPool, ptr);
throw std::runtime_error("calloc failed with unexpected error");
}

umfPoolFree(hPool, ptr);

return supported;
}

Expand Down
2 changes: 1 addition & 1 deletion test/unified_malloc_framework/memoryPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ TEST_P(umfPoolTest, multiThreadedMallocFreeRandomSizes) {

std::vector<std::thread> threads;
for (int i = 0; i < NTHREADS; i++) {
threads.emplace_back(poolMalloc, rand() % 64 + 1, pool.get());
threads.emplace_back(poolMalloc, (rand() % 16) * 8, pool.get());
}

for (auto &thread : threads) {
Expand Down
2 changes: 2 additions & 0 deletions test/unified_malloc_framework/memoryPoolAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ TEST_F(test, getLastFailedMemoryProvider) {
auto ptr = umfPoolMalloc(pool.get(), allocSize);
ASSERT_NE(ptr, nullptr);
ASSERT_EQ(umfGetLastFailedMemoryProvider(), nullptr);
umfPoolFree(pool.get(), ptr);

// make provider return an error during allocation
allocResult = UMF_RESULT_ERROR_UNKNOWN;
Expand All @@ -280,6 +281,7 @@ TEST_F(test, getLastFailedMemoryProvider) {
ASSERT_EQ(std::string_view(
umfMemoryProviderGetName(umfGetLastFailedMemoryProvider())),
"provider2");
umfPoolFree(pool.get(), ptr);

// error in another thread should not impact umfGetLastFailedMemoryProvider on this thread
allocResult = UMF_RESULT_ERROR_UNKNOWN;
Expand Down