@@ -416,10 +416,9 @@ static umf_result_t trackingInitialize(void *params, void **ret) {
416416 return UMF_RESULT_SUCCESS ;
417417}
418418
419- // TODO clearing the tracker is a temporary solution and should be removed.
420- // The tracker should be cleared using the provider's free() operation.
421- static void clear_tracker_for_the_pool (umf_memory_tracker_handle_t hTracker ,
422- umf_memory_pool_handle_t pool ) {
419+ #ifndef NDEBUG
420+ static void check_if_tracker_is_empty (umf_memory_tracker_handle_t hTracker ,
421+ umf_memory_pool_handle_t pool ) {
423422 uintptr_t rkey ;
424423 void * rvalue ;
425424 size_t n_items = 0 ;
@@ -428,40 +427,30 @@ static void clear_tracker_for_the_pool(umf_memory_tracker_handle_t hTracker,
428427 while (1 == critnib_find ((critnib * )hTracker -> map , last_key , FIND_G , & rkey ,
429428 & rvalue )) {
430429 tracker_value_t * value = (tracker_value_t * )rvalue ;
431- if (value -> pool != pool && pool != NULL ) {
432- last_key = rkey ;
433- continue ;
430+ if (value -> pool == pool || pool == NULL ) {
431+ n_items ++ ;
434432 }
435433
436- n_items ++ ;
437-
438- void * removed_value = critnib_remove (hTracker -> map , rkey );
439- assert (removed_value == rvalue );
440- umf_ba_free (hTracker -> tracker_allocator , removed_value );
441-
442434 last_key = rkey ;
443435 }
444436
445- #ifndef NDEBUG
446- // print error messages only if provider supports the free() operation
447437 if (n_items ) {
448- if (pool ) {
449- LOG_ERR (
450- "tracking provider of pool %p is not empty! (%zu items left)" ,
451- (void * )pool , n_items );
452- } else {
453- LOG_ERR ("tracking provider is not empty! (%zu items left)" ,
454- n_items );
438+ // Do not log the error if we are running in the proxy library,
439+ // because it may need those resources till
440+ // the very end of exiting the application.
441+ if (!utils_is_running_in_proxy_lib ()) {
442+ if (pool ) {
443+ LOG_ERR ("tracking provider of pool %p is not empty! (%zu items "
444+ "left)" ,
445+ (void * )pool , n_items );
446+ } else {
447+ LOG_ERR ("tracking provider is not empty! (%zu items left)" ,
448+ n_items );
449+ }
455450 }
456451 }
457- #else /* DEBUG */
458- (void )n_items ; // unused in DEBUG build
459- #endif /* DEBUG */
460- }
461-
462- static void clear_tracker (umf_memory_tracker_handle_t hTracker ) {
463- clear_tracker_for_the_pool (hTracker , NULL );
464452}
453+ #endif /* NDEBUG */
465454
466455static void trackingFinalize (void * provider ) {
467456 umf_tracking_memory_provider_t * p =
@@ -471,12 +460,9 @@ static void trackingFinalize(void *provider) {
471460
472461 critnib_delete (p -> ipcCache );
473462
474- // Do not clear the tracker if we are running in the proxy library,
475- // because it may need those resources till
476- // the very end of exiting the application.
477- if (!utils_is_running_in_proxy_lib ()) {
478- clear_tracker_for_the_pool (p -> hTracker , p -> pool );
479- }
463+ #ifndef NDEBUG
464+ check_if_tracker_is_empty (p -> hTracker , p -> pool );
465+ #endif /* NDEBUG */
480466
481467 umf_ba_global_free (provider );
482468}
@@ -860,7 +846,9 @@ void umfMemoryTrackerDestroy(umf_memory_tracker_handle_t handle) {
860846 return ;
861847 }
862848
863- clear_tracker (handle );
849+ #ifndef NDEBUG
850+ check_if_tracker_is_empty (handle , NULL );
851+ #endif /* NDEBUG */
864852
865853 // We have to zero all inner pointers,
866854 // because the tracker handle can be copied
0 commit comments