23
23
24
24
// global base allocator used by all providers and pools
25
25
static UTIL_ONCE_FLAG ba_is_initialized = UTIL_ONCE_FLAG_INIT ;
26
+ static bool ba_is_destroyed = false;
26
27
27
28
#define ALLOC_METADATA_SIZE (sizeof(size_t))
28
29
29
30
// allocation classes need to be consecutive powers of 2
30
- #define ALLOCATION_CLASSES \
31
- { 16, 32, 64, 128, 256 }
31
+ #define ALLOCATION_CLASSES {16, 32, 64, 128, 256}
32
32
#define NUM_ALLOCATION_CLASSES 5
33
33
34
34
struct base_alloc_t {
@@ -40,6 +40,8 @@ struct base_alloc_t {
40
40
static struct base_alloc_t BASE_ALLOC = {.ac_sizes = ALLOCATION_CLASSES };
41
41
42
42
void umf_ba_destroy_global (void ) {
43
+ ba_is_destroyed = true;
44
+
43
45
for (int i = 0 ; i < NUM_ALLOCATION_CLASSES ; i ++ ) {
44
46
if (BASE_ALLOC .ac [i ]) {
45
47
umf_ba_destroy (BASE_ALLOC .ac [i ]);
@@ -48,10 +50,12 @@ void umf_ba_destroy_global(void) {
48
50
}
49
51
50
52
// 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 ));
53
+ static UTIL_ONCE_FLAG set_once = UTIL_ONCE_FLAG_INIT ;
54
+ memcpy (& ba_is_initialized , & set_once , sizeof (ba_is_initialized ));
53
55
}
54
56
57
+ bool umf_ba_global_is_destroyed (void ) { return ba_is_destroyed ; }
58
+
55
59
static void umf_ba_create_global (void ) {
56
60
for (int i = 0 ; i < NUM_ALLOCATION_CLASSES ; i ++ ) {
57
61
// allocation classes need to be powers of 2
@@ -202,6 +206,11 @@ void umf_ba_global_free(void *ptr) {
202
206
return ;
203
207
}
204
208
209
+ if (ba_is_destroyed ) {
210
+ LOG_WARN ("base_alloc: calling free after the base alloc is destroyed" );
211
+ return ;
212
+ }
213
+
205
214
size_t total_size ;
206
215
ptr = get_original_alloc (ptr , & total_size , NULL );
207
216
0 commit comments