Skip to content

Commit 93b8be2

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

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
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

src/utils/utils_common.h

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

73+
// check if we are running in the proxy library with a size threshold
74+
static inline int utils_is_running_in_proxy_lib_with_size_threshold(void) {
75+
return (utils_env_var_get_str("LD_PRELOAD", "libumf_proxy.so") &&
76+
utils_env_var_get_str("UMF_PROXY", "size.threshold="))
77+
? 1
78+
: 0;
79+
}
80+
7381
// utils_parse_var - Parses var for a prefix,
7482
// optionally identifying a following argument.
7583
// Parameters:

0 commit comments

Comments
 (0)