From a2f13cd4d3cef39556ed9885bf0fa49100a22694 Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Mon, 5 May 2025 11:03:19 +0100 Subject: [PATCH] Check global state destruction in destructors In some cases the global state may have been destroyed when we reach `umfDestroyPool` or `umfDestroyProvider`, in which case actually going through with the destruction will cause segmentation faults. The way the global state is managed should maybe be re-worked, but this should be an okay workaround to avoid segmentation faults until then. --- src/memory_pool.c | 4 ++++ src/memory_provider.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/memory_pool.c b/src/memory_pool.c index 985600d2a..2f0b82c2c 100644 --- a/src/memory_pool.c +++ b/src/memory_pool.c @@ -115,6 +115,10 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops, } void umfPoolDestroy(umf_memory_pool_handle_t hPool) { + if (umf_ba_global_is_destroyed()) { + return; + } + hPool->ops.finalize(hPool->pool_priv); umf_memory_provider_handle_t hUpstreamProvider = NULL; diff --git a/src/memory_provider.c b/src/memory_provider.c index 627ad23ac..d32fcdcd6 100644 --- a/src/memory_provider.c +++ b/src/memory_provider.c @@ -223,7 +223,7 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, } void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider) { - if (hProvider) { + if (hProvider && !umf_ba_global_is_destroyed()) { hProvider->ops.finalize(hProvider->provider_priv); umf_ba_global_free(hProvider); }