Skip to content

Commit a69492d

Browse files
npmillerlukaszstolarczuk
authored andcommitted
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.
1 parent a5c3d26 commit a69492d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/memory_pool.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
8585
}
8686

8787
void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
88+
if (umf_ba_global_is_destroyed()) {
89+
return;
90+
}
91+
8892
hPool->ops.finalize(hPool->pool_priv);
8993

9094
umf_memory_provider_handle_t hUpstreamProvider = NULL;

src/memory_provider.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
194194
}
195195

196196
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider) {
197-
if (hProvider) {
197+
if (hProvider && !umf_ba_global_is_destroyed()) {
198198
hProvider->ops.finalize(hProvider->provider_priv);
199199
umf_ba_global_free(hProvider);
200200
}

0 commit comments

Comments
 (0)