From 439ea94a971be6e4adbd8e976c552b9ee541b135 Mon Sep 17 00:00:00 2001 From: Sergei Vinogradov Date: Sun, 13 Oct 2024 01:47:27 +0200 Subject: [PATCH] Fix umfPoolDestroy to destroy providers in the right order --- src/memory_pool.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/memory_pool.c b/src/memory_pool.c index c45ddafe7..4a85955ef 100644 --- a/src/memory_pool.c +++ b/src/memory_pool.c @@ -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)