Skip to content

Fix umfPoolDestroy to destroy providers in the right order #794

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
merged 1 commit into from
Oct 14, 2024
Merged
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
14 changes: 8 additions & 6 deletions src/memory_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,

void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
hPool->ops.finalize(hPool->pool_priv);
if (hPool->flags & UMF_POOL_CREATE_FLAG_OWN_PROVIDER) {
// Destroy associated memory provider.
umf_memory_provider_handle_t hProvider = NULL;
umfPoolGetMemoryProvider(hPool, &hProvider);
umfMemoryProviderDestroy(hProvider);
}

umf_memory_provider_handle_t hUpstreamProvider = NULL;
umfPoolGetMemoryProvider(hPool, &hUpstreamProvider);

if (!(hPool->flags & UMF_POOL_CREATE_FLAG_DISABLE_TRACKING)) {
// Destroy tracking provider.
umfMemoryProviderDestroy(hPool->provider);
}

if (hPool->flags & UMF_POOL_CREATE_FLAG_OWN_PROVIDER) {
// Destroy associated memory provider.
umfMemoryProviderDestroy(hUpstreamProvider);
}

LOG_INFO("Memory pool destroyed: %p", (void *)hPool);

// TODO: this free keeps memory in base allocator, so it can lead to OOM in some scenarios (it should be optimized)
Expand Down
Loading