@@ -36,9 +36,9 @@ struct umf_ba_main_pool_meta_t {
36
36
size_t chunk_size ; // size of all memory chunks in this pool
37
37
os_mutex_t free_lock ; // lock of free_list
38
38
umf_ba_chunk_t * free_list ; // list of free chunks
39
+ size_t n_allocs ; // number of allocated chunks
39
40
#ifndef NDEBUG
40
41
size_t n_pools ;
41
- size_t n_allocs ;
42
42
size_t n_chunks ;
43
43
#endif /* NDEBUG */
44
44
};
@@ -135,9 +135,9 @@ umf_ba_pool_t *umf_ba_create(size_t size) {
135
135
pool -> metadata .pool_size = pool_size ;
136
136
pool -> metadata .chunk_size = chunk_size ;
137
137
pool -> next_pool = NULL ; // this is the only pool now
138
+ pool -> metadata .n_allocs = 0 ;
138
139
#ifndef NDEBUG
139
140
pool -> metadata .n_pools = 1 ;
140
- pool -> metadata .n_allocs = 0 ;
141
141
pool -> metadata .n_chunks = 0 ;
142
142
#endif /* NDEBUG */
143
143
@@ -187,8 +187,8 @@ void *umf_ba_alloc(umf_ba_pool_t *pool) {
187
187
188
188
umf_ba_chunk_t * chunk = pool -> metadata .free_list ;
189
189
pool -> metadata .free_list = pool -> metadata .free_list -> next ;
190
- #ifndef NDEBUG
191
190
pool -> metadata .n_allocs ++ ;
191
+ #ifndef NDEBUG
192
192
ba_debug_checks (pool );
193
193
#endif /* NDEBUG */
194
194
util_mutex_unlock (& pool -> metadata .free_lock );
@@ -230,18 +230,30 @@ void umf_ba_free(umf_ba_pool_t *pool, void *ptr) {
230
230
assert (pool_contains_pointer (pool , ptr ));
231
231
chunk -> next = pool -> metadata .free_list ;
232
232
pool -> metadata .free_list = chunk ;
233
- #ifndef NDEBUG
234
233
pool -> metadata .n_allocs -- ;
234
+ #ifndef NDEBUG
235
235
ba_debug_checks (pool );
236
236
#endif /* NDEBUG */
237
237
util_mutex_unlock (& pool -> metadata .free_lock );
238
238
}
239
239
240
240
void umf_ba_destroy (umf_ba_pool_t * pool ) {
241
+ // Do not destroy if we are running in the proxy library,
242
+ // because it may need those resources till
243
+ // the very end of exiting the application.
244
+ if (pool -> metadata .n_allocs && is_running_in_proxy_lib ()) {
245
+ return ;
246
+ }
247
+
241
248
#ifndef NDEBUG
242
- assert (pool -> metadata .n_allocs == 0 );
243
249
ba_debug_checks (pool );
250
+ if (pool -> metadata .n_allocs ) {
251
+ fprintf (stderr , "umf_ba_destroy(): pool->metadata.n_allocs = %zu\n" ,
252
+ pool -> metadata .n_allocs );
253
+ assert (pool -> metadata .n_allocs == 0 );
254
+ }
244
255
#endif /* NDEBUG */
256
+
245
257
size_t size = pool -> metadata .pool_size ;
246
258
umf_ba_next_pool_t * current_pool ;
247
259
umf_ba_next_pool_t * next_pool = pool -> next_pool ;
0 commit comments