@@ -36,9 +36,9 @@ struct umf_ba_main_pool_meta_t {
3636 size_t chunk_size ; // size of all memory chunks in this pool
3737 os_mutex_t free_lock ; // lock of free_list
3838 umf_ba_chunk_t * free_list ; // list of free chunks
39+ size_t n_allocs ; // number of allocated chunks
3940#ifndef NDEBUG
4041 size_t n_pools ;
41- size_t n_allocs ;
4242 size_t n_chunks ;
4343#endif /* NDEBUG */
4444};
@@ -135,9 +135,9 @@ umf_ba_pool_t *umf_ba_create(size_t size) {
135135 pool -> metadata .pool_size = pool_size ;
136136 pool -> metadata .chunk_size = chunk_size ;
137137 pool -> next_pool = NULL ; // this is the only pool now
138+ pool -> metadata .n_allocs = 0 ;
138139#ifndef NDEBUG
139140 pool -> metadata .n_pools = 1 ;
140- pool -> metadata .n_allocs = 0 ;
141141 pool -> metadata .n_chunks = 0 ;
142142#endif /* NDEBUG */
143143
@@ -187,8 +187,8 @@ void *umf_ba_alloc(umf_ba_pool_t *pool) {
187187
188188 umf_ba_chunk_t * chunk = pool -> metadata .free_list ;
189189 pool -> metadata .free_list = pool -> metadata .free_list -> next ;
190- #ifndef NDEBUG
191190 pool -> metadata .n_allocs ++ ;
191+ #ifndef NDEBUG
192192 ba_debug_checks (pool );
193193#endif /* NDEBUG */
194194 util_mutex_unlock (& pool -> metadata .free_lock );
@@ -230,18 +230,30 @@ void umf_ba_free(umf_ba_pool_t *pool, void *ptr) {
230230 assert (pool_contains_pointer (pool , ptr ));
231231 chunk -> next = pool -> metadata .free_list ;
232232 pool -> metadata .free_list = chunk ;
233- #ifndef NDEBUG
234233 pool -> metadata .n_allocs -- ;
234+ #ifndef NDEBUG
235235 ba_debug_checks (pool );
236236#endif /* NDEBUG */
237237 util_mutex_unlock (& pool -> metadata .free_lock );
238238}
239239
240240void 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+
241248#ifndef NDEBUG
242- assert (pool -> metadata .n_allocs == 0 );
243249 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+ }
244255#endif /* NDEBUG */
256+
245257 size_t size = pool -> metadata .pool_size ;
246258 umf_ba_next_pool_t * current_pool ;
247259 umf_ba_next_pool_t * next_pool = pool -> next_pool ;
0 commit comments