1313#include "ipc_cache.h"
1414#include "memspace_internal.h"
1515#include "provider_tracking.h"
16+ #include "utils_common.h"
1617#include "utils_log.h"
1718#if !defined(UMF_NO_HWLOC )
1819#include "topology.h"
@@ -30,11 +31,20 @@ int umfInit(void) {
3031 LOG_ERR ("Failed to create memory tracker" );
3132 return -1 ;
3233 }
34+
35+ LOG_DEBUG ("UMF tracker created" );
36+
3337 umf_result_t umf_result = umfIpcCacheGlobalInit ();
3438 if (umf_result != UMF_RESULT_SUCCESS ) {
3539 LOG_ERR ("Failed to initialize IPC cache" );
3640 return -1 ;
3741 }
42+
43+ LOG_DEBUG ("UMF IPC cache initialized" );
44+ }
45+
46+ if (TRACKER ) {
47+ LOG_DEBUG ("UMF library initialized" );
3848 }
3949
4050 return 0 ;
@@ -50,12 +60,26 @@ void umfTearDown(void) {
5060 umfDestroyTopology ();
5161#endif
5262 umfIpcCacheGlobalTearDown ();
63+
64+ if (utils_is_running_in_proxy_lib_with_size_threshold ()) {
65+ // We cannot destroy the TRACKER nor the base allocator
66+ // when we are running in the proxy library with a size threshold,
67+ // because it could result in calling the system free() with an invalid pointer
68+ // and a segfault as a result.
69+ goto fini_umfTearDown ;
70+ }
71+
5372 // make sure TRACKER is not used after being destroyed
5473 umf_memory_tracker_handle_t t = TRACKER ;
5574 TRACKER = NULL ;
5675 umfMemoryTrackerDestroy (t );
76+ LOG_DEBUG ("UMF tracker destroyed" );
5777
5878 umf_ba_destroy_global ();
79+ LOG_DEBUG ("UMF base allocator destroyed" );
80+
81+ fini_umfTearDown :
82+ LOG_DEBUG ("UMF library finalized" );
5983 }
6084}
6185
0 commit comments