Skip to content

Commit a2f13cd

Browse files
committed
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 4b1a946 commit a2f13cd

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
@@ -115,6 +115,10 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
115115
}
116116

117117
void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
118+
if (umf_ba_global_is_destroyed()) {
119+
return;
120+
}
121+
118122
hPool->ops.finalize(hPool->pool_priv);
119123

120124
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
@@ -223,7 +223,7 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
223223
}
224224

225225
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider) {
226-
if (hProvider) {
226+
if (hProvider && !umf_ba_global_is_destroyed()) {
227227
hProvider->ops.finalize(hProvider->provider_priv);
228228
umf_ba_global_free(hProvider);
229229
}

0 commit comments

Comments
 (0)