1212#include "base_alloc_global.h"
1313#include "memspace_internal.h"
1414#include "provider_tracking.h"
15+ #include "utils_common.h"
1516#include "utils_log.h"
1617#if !defined(UMF_NO_HWLOC )
1718#include "topology.h"
@@ -25,6 +26,11 @@ int umfInit(void) {
2526 if (utils_fetch_and_add64 (& umfRefCount , 1 ) == 0 ) {
2627 utils_log_init ();
2728 TRACKER = umfMemoryTrackerCreate ();
29+ LOG_DEBUG ("UMF tracker created" );
30+ }
31+
32+ if (TRACKER ) {
33+ LOG_DEBUG ("UMF library initialized" );
2834 }
2935
3036 return (TRACKER ) ? 0 : -1 ;
@@ -39,12 +45,26 @@ void umfTearDown(void) {
3945 umfMemspaceLowestLatencyDestroy ();
4046 umfDestroyTopology ();
4147#endif
48+
49+ if (utils_is_running_in_proxy_lib_with_size_threshold ()) {
50+ // We cannot destroy the TRACKER nor the base allocator
51+ // when we are running in the proxy library with a size threshold,
52+ // because it could lead to calling the system free() with an invalid pointer
53+ // and a segfault as a result.
54+ goto fini_umfTearDown ;
55+ }
56+
4257 // make sure TRACKER is not used after being destroyed
4358 umf_memory_tracker_handle_t t = TRACKER ;
4459 TRACKER = NULL ;
4560 umfMemoryTrackerDestroy (t );
61+ LOG_DEBUG ("UMF tracker destroyed" );
4662
4763 umf_ba_destroy_global ();
64+ LOG_DEBUG ("UMF base allocator destroyed" );
65+
66+ fini_umfTearDown :
67+ LOG_DEBUG ("UMF library finalized" );
4868 }
4969}
5070
0 commit comments