13
13
#include "ipc_cache.h"
14
14
#include "memspace_internal.h"
15
15
#include "provider_tracking.h"
16
+ #include "utils_common.h"
16
17
#include "utils_log.h"
17
18
#if !defined(UMF_NO_HWLOC )
18
19
#include "topology.h"
@@ -30,11 +31,20 @@ int umfInit(void) {
30
31
LOG_ERR ("Failed to create memory tracker" );
31
32
return -1 ;
32
33
}
34
+
35
+ LOG_DEBUG ("UMF tracker created" );
36
+
33
37
umf_result_t umf_result = umfIpcCacheGlobalInit ();
34
38
if (umf_result != UMF_RESULT_SUCCESS ) {
35
39
LOG_ERR ("Failed to initialize IPC cache" );
36
40
return -1 ;
37
41
}
42
+
43
+ LOG_DEBUG ("UMF IPC cache initialized" );
44
+ }
45
+
46
+ if (TRACKER ) {
47
+ LOG_DEBUG ("UMF library initialized" );
38
48
}
39
49
40
50
return 0 ;
@@ -50,12 +60,26 @@ void umfTearDown(void) {
50
60
umfDestroyTopology ();
51
61
#endif
52
62
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 lead to calling the system free() with an invalid pointer
68
+ // and a segfault as a result.
69
+ goto fini_umfTearDown ;
70
+ }
71
+
53
72
// make sure TRACKER is not used after being destroyed
54
73
umf_memory_tracker_handle_t t = TRACKER ;
55
74
TRACKER = NULL ;
56
75
umfMemoryTrackerDestroy (t );
76
+ LOG_DEBUG ("UMF tracker destroyed" );
57
77
58
78
umf_ba_destroy_global ();
79
+ LOG_DEBUG ("UMF base allocator destroyed" );
80
+
81
+ fini_umfTearDown :
82
+ LOG_DEBUG ("UMF library finalized" );
59
83
}
60
84
}
61
85
0 commit comments