Skip to content

Commit 2172179

Browse files
committed
Do not destroy tracker in umfTearDown() under the proxy library
Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent cf64635 commit 2172179

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/base_alloc/base_alloc_global.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static void umf_ba_create_global(void) {
6767

6868
size_t smallestSize = BASE_ALLOC.ac_sizes[0];
6969
BASE_ALLOC.smallest_ac_size_log2 = log2Utils(smallestSize);
70+
71+
LOG_DEBUG("UMF base allocator created");
7072
}
7173

7274
// returns index of the allocation class for a given size

src/libumf.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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()
68+
// with an invalid pointer and a segfault.
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

src/utils/utils_common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ static inline int utils_is_running_in_proxy_lib(void) {
7575
return utils_env_var_get_str("LD_PRELOAD", "libumf_proxy.so") ? 1 : 0;
7676
}
7777

78+
// check if we are running in the proxy library with a size threshold
79+
static inline int utils_is_running_in_proxy_lib_with_size_threshold(void) {
80+
return (utils_env_var_get_str("LD_PRELOAD", "libumf_proxy.so") &&
81+
utils_env_var_get_str("UMF_PROXY", "size.threshold="))
82+
? 1
83+
: 0;
84+
}
85+
7886
// utils_parse_var - Parses var for a prefix,
7987
// optionally identifying a following argument.
8088
// Parameters:

0 commit comments

Comments
 (0)