@@ -425,10 +425,9 @@ static umf_result_t trackingInitialize(void *params, void **ret) {
425
425
return UMF_RESULT_SUCCESS ;
426
426
}
427
427
428
- // TODO clearing the tracker is a temporary solution and should be removed.
429
- // The tracker should be cleared using the provider's free() operation.
430
- static void clear_tracker_for_the_pool (umf_memory_tracker_handle_t hTracker ,
431
- umf_memory_pool_handle_t pool ) {
428
+ #ifndef NDEBUG
429
+ static void check_if_tracker_is_empty (umf_memory_tracker_handle_t hTracker ,
430
+ umf_memory_pool_handle_t pool ) {
432
431
uintptr_t rkey ;
433
432
void * rvalue ;
434
433
size_t n_items = 0 ;
@@ -437,41 +436,34 @@ static void clear_tracker_for_the_pool(umf_memory_tracker_handle_t hTracker,
437
436
while (1 == critnib_find ((critnib * )hTracker -> alloc_segments_map , last_key ,
438
437
FIND_G , & rkey , & rvalue )) {
439
438
tracker_alloc_info_t * value = (tracker_alloc_info_t * )rvalue ;
440
- if (value -> pool != pool && pool != NULL ) {
441
- last_key = rkey ;
442
- continue ;
439
+ if (value -> pool == pool || pool == NULL ) {
440
+ n_items ++ ;
443
441
}
444
442
445
- n_items ++ ;
446
-
447
- void * removed_value =
448
- critnib_remove (hTracker -> alloc_segments_map , rkey );
449
- assert (removed_value == rvalue );
450
- umf_ba_free (hTracker -> alloc_info_allocator , removed_value );
451
-
452
443
last_key = rkey ;
453
444
}
454
445
455
- #ifndef NDEBUG
456
- // print error messages only if provider supports the free() operation
457
446
if (n_items ) {
458
- if (pool ) {
459
- LOG_ERR (
460
- "tracking provider of pool %p is not empty! (%zu items left)" ,
461
- (void * )pool , n_items );
462
- } else {
463
- LOG_ERR ("tracking provider is not empty! (%zu items left)" ,
464
- n_items );
447
+ // Do not log the error if we are running in the proxy library,
448
+ // because it may need those resources till
449
+ // the very end of exiting the application.
450
+ if (!utils_is_running_in_proxy_lib ()) {
451
+ if (pool ) {
452
+ LOG_ERR ("tracking provider of pool %p is not empty! (%zu items "
453
+ "left)" ,
454
+ (void * )pool , n_items );
455
+ } else {
456
+ LOG_ERR ("tracking provider is not empty! (%zu items left)" ,
457
+ n_items );
458
+ }
459
+
460
+ #ifdef UMF_DEVELOPER_MODE
461
+ assert (n_items == 0 && "tracking provider is not empty!" );
462
+ #endif
465
463
}
466
464
}
467
- #else /* DEBUG */
468
- (void )n_items ; // unused in DEBUG build
469
- #endif /* DEBUG */
470
- }
471
-
472
- static void clear_tracker (umf_memory_tracker_handle_t hTracker ) {
473
- clear_tracker_for_the_pool (hTracker , NULL );
474
465
}
466
+ #endif /* NDEBUG */
475
467
476
468
static void trackingFinalize (void * provider ) {
477
469
umf_tracking_memory_provider_t * p =
@@ -481,12 +473,9 @@ static void trackingFinalize(void *provider) {
481
473
482
474
critnib_delete (p -> ipcCache );
483
475
484
- // Do not clear the tracker if we are running in the proxy library,
485
- // because it may need those resources till
486
- // the very end of exiting the application.
487
- if (!utils_is_running_in_proxy_lib ()) {
488
- clear_tracker_for_the_pool (p -> hTracker , p -> pool );
489
- }
476
+ #ifndef NDEBUG
477
+ check_if_tracker_is_empty (p -> hTracker , p -> pool );
478
+ #endif /* NDEBUG */
490
479
491
480
umf_ba_global_free (provider );
492
481
}
@@ -870,7 +859,9 @@ void umfMemoryTrackerDestroy(umf_memory_tracker_handle_t handle) {
870
859
return ;
871
860
}
872
861
873
- clear_tracker (handle );
862
+ #ifndef NDEBUG
863
+ check_if_tracker_is_empty (handle , NULL );
864
+ #endif /* NDEBUG */
874
865
875
866
// We have to zero all inner pointers,
876
867
// because the tracker handle can be copied
0 commit comments