12
12
#include "base_alloc_global.h"
13
13
#include "memspace_internal.h"
14
14
#include "provider_tracking.h"
15
+ #include "utils_common.h"
15
16
#include "utils_log.h"
16
17
#if !defined(UMF_NO_HWLOC )
17
18
#include "topology.h"
@@ -25,6 +26,11 @@ int umfInit(void) {
25
26
if (utils_fetch_and_add64 (& umfRefCount , 1 ) == 0 ) {
26
27
utils_log_init ();
27
28
TRACKER = umfMemoryTrackerCreate ();
29
+ LOG_DEBUG ("UMF tracker created" );
30
+ }
31
+
32
+ if (TRACKER ) {
33
+ LOG_DEBUG ("UMF library initialized" );
28
34
}
29
35
30
36
return (TRACKER ) ? 0 : -1 ;
@@ -39,12 +45,26 @@ void umfTearDown(void) {
39
45
umfMemspaceLowestLatencyDestroy ();
40
46
umfDestroyTopology ();
41
47
#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
+
42
57
// make sure TRACKER is not used after being destroyed
43
58
umf_memory_tracker_handle_t t = TRACKER ;
44
59
TRACKER = NULL ;
45
60
umfMemoryTrackerDestroy (t );
61
+ LOG_DEBUG ("UMF tracker destroyed" );
46
62
47
63
umf_ba_destroy_global ();
64
+ LOG_DEBUG ("UMF base allocator destroyed" );
65
+
66
+ fini_umfTearDown :
67
+ LOG_DEBUG ("UMF library finalized" );
48
68
}
49
69
}
50
70
0 commit comments