@@ -425,10 +425,9 @@ static umf_result_t trackingInitialize(void *params, void **ret) {
425425 return UMF_RESULT_SUCCESS ;
426426}
427427
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 ) {
432431 uintptr_t rkey ;
433432 void * rvalue ;
434433 size_t n_items = 0 ;
@@ -437,41 +436,34 @@ static void clear_tracker_for_the_pool(umf_memory_tracker_handle_t hTracker,
437436 while (1 == critnib_find ((critnib * )hTracker -> alloc_segments_map , last_key ,
438437 FIND_G , & rkey , & rvalue )) {
439438 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 ++ ;
443441 }
444442
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-
452443 last_key = rkey ;
453444 }
454445
455- #ifndef NDEBUG
456- // print error messages only if provider supports the free() operation
457446 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
465463 }
466464 }
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 );
474465}
466+ #endif /* NDEBUG */
475467
476468static void trackingFinalize (void * provider ) {
477469 umf_tracking_memory_provider_t * p =
@@ -481,12 +473,9 @@ static void trackingFinalize(void *provider) {
481473
482474 critnib_delete (p -> ipcCache );
483475
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 */
490479
491480 umf_ba_global_free (provider );
492481}
@@ -870,7 +859,9 @@ void umfMemoryTrackerDestroy(umf_memory_tracker_handle_t handle) {
870859 return ;
871860 }
872861
873- clear_tracker (handle );
862+ #ifndef NDEBUG
863+ check_if_tracker_is_empty (handle , NULL );
864+ #endif /* NDEBUG */
874865
875866 // We have to zero all inner pointers,
876867 // because the tracker handle can be copied
0 commit comments