2323
2424// global base allocator used by all providers and pools
2525static UTIL_ONCE_FLAG ba_is_initialized = UTIL_ONCE_FLAG_INIT ;
26+ static bool ba_is_destroyed = false;
2627
2728#define ALLOC_METADATA_SIZE (sizeof(size_t))
2829
@@ -40,6 +41,8 @@ struct base_alloc_t {
4041static struct base_alloc_t BASE_ALLOC = {.ac_sizes = ALLOCATION_CLASSES };
4142
4243void umf_ba_destroy_global (void ) {
44+ ba_is_destroyed = true;
45+
4346 for (int i = 0 ; i < NUM_ALLOCATION_CLASSES ; i ++ ) {
4447 if (BASE_ALLOC .ac [i ]) {
4548 umf_ba_destroy (BASE_ALLOC .ac [i ]);
@@ -48,10 +51,12 @@ void umf_ba_destroy_global(void) {
4851 }
4952
5053 // portable version of "ba_is_initialized = UTIL_ONCE_FLAG_INIT;"
51- static UTIL_ONCE_FLAG is_initialized = UTIL_ONCE_FLAG_INIT ;
52- memcpy (& ba_is_initialized , & is_initialized , sizeof (ba_is_initialized ));
54+ static UTIL_ONCE_FLAG set_once = UTIL_ONCE_FLAG_INIT ;
55+ memcpy (& ba_is_initialized , & set_once , sizeof (ba_is_initialized ));
5356}
5457
58+ bool umf_ba_global_is_destroyed (void ) { return ba_is_destroyed ; }
59+
5560static void umf_ba_create_global (void ) {
5661 for (int i = 0 ; i < NUM_ALLOCATION_CLASSES ; i ++ ) {
5762 // allocation classes need to be powers of 2
@@ -202,6 +207,11 @@ void umf_ba_global_free(void *ptr) {
202207 return ;
203208 }
204209
210+ if (ba_is_destroyed ) {
211+ LOG_WARN ("base_alloc: calling free after the base alloc is destroyed" );
212+ return ;
213+ }
214+
205215 size_t total_size ;
206216 ptr = get_original_alloc (ptr , & total_size , NULL );
207217
0 commit comments