@@ -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,30 @@ 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+ }
465459 }
466460 }
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 );
474461}
462+ #endif /* NDEBUG */
475463
476464static void trackingFinalize (void * provider ) {
477465 umf_tracking_memory_provider_t * p =
@@ -481,12 +469,9 @@ static void trackingFinalize(void *provider) {
481469
482470 critnib_delete (p -> ipcCache );
483471
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- }
472+ #ifndef NDEBUG
473+ check_if_tracker_is_empty (p -> hTracker , p -> pool );
474+ #endif /* NDEBUG */
490475
491476 umf_ba_global_free (provider );
492477}
@@ -870,7 +855,9 @@ void umfMemoryTrackerDestroy(umf_memory_tracker_handle_t handle) {
870855 return ;
871856 }
872857
873- clear_tracker (handle );
858+ #ifndef NDEBUG
859+ check_if_tracker_is_empty (handle , NULL );
860+ #endif /* NDEBUG */
874861
875862 // We have to zero all inner pointers,
876863 // because the tracker handle can be copied
0 commit comments