Skip to content

Commit

Permalink
Merge pull request #794 from vinser52/svinogra.minor_fixes
Browse files Browse the repository at this point in the history
Fix umfPoolDestroy to destroy providers in the right order
  • Loading branch information
ldorau authored Oct 14, 2024
2 parents 0cac080 + 439ea94 commit d6470fc
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit d6470fc

Please sign in to comment.