Skip to content

Commit d8bac48

Browse files
committed
Add WA for the issue
This WA for the issue: #894 It protects us from a recursion in malloc_usable_size() when the JEMALLOC proxy_lib_pool is used. TODO: remove this WA when the issue is fixed. Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent 6d6ae19 commit d8bac48

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/proxy_lib/proxy_lib.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ static umf_memory_pool_handle_t Proxy_pool = NULL;
128128
// it protects us from recursion in umfPool*()
129129
static __TLS int was_called_from_umfPool = 0;
130130

131+
// This WA for the issue:
132+
// https://github.com/oneapi-src/unified-memory-framework/issues/894
133+
// It protects us from a recursion in malloc_usable_size()
134+
// when the JEMALLOC proxy_lib_pool is used.
135+
// TODO remove this WA when the issue is fixed.
136+
static __TLS int was_called_from_malloc_usable_size = 0;
137+
131138
/*****************************************************************************/
132139
/*** The constructor and destructor of the proxy library *********************/
133140
/*****************************************************************************/
@@ -454,15 +461,18 @@ size_t malloc_usable_size(void *ptr) {
454461
return 0; // unsupported in case of the ba_leak allocator
455462
}
456463

457-
if (Proxy_pool && (umfPoolByPtr(ptr) == Proxy_pool)) {
464+
if (!was_called_from_malloc_usable_size && Proxy_pool &&
465+
(umfPoolByPtr(ptr) == Proxy_pool)) {
466+
was_called_from_malloc_usable_size = 1;
458467
was_called_from_umfPool = 1;
459468
size_t size = umfPoolMallocUsableSize(Proxy_pool, ptr);
460469
was_called_from_umfPool = 0;
470+
was_called_from_malloc_usable_size = 0;
461471
return size;
462472
}
463473

464474
#ifndef _WIN32
465-
if (Size_threshold_value) {
475+
if (!was_called_from_malloc_usable_size && Size_threshold_value) {
466476
return System_malloc_usable_size(ptr);
467477
}
468478
#endif /* _WIN32 */

0 commit comments

Comments
 (0)