Skip to content

Commit f99b905

Browse files
committed
Add WA for the issue
This WA for the issue: oneapi-src#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 bb7d311 commit f99b905

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
/*****************************************************************************/
@@ -472,15 +479,18 @@ size_t malloc_usable_size(void *ptr) {
472479
return 0; // unsupported in case of the ba_leak allocator
473480
}
474481

475-
if (Proxy_pool && (umfPoolByPtr(ptr) == Proxy_pool)) {
482+
if (!was_called_from_malloc_usable_size && Proxy_pool &&
483+
(umfPoolByPtr(ptr) == Proxy_pool)) {
484+
was_called_from_malloc_usable_size = 1;
476485
was_called_from_umfPool = 1;
477486
size_t size = umfPoolMallocUsableSize(Proxy_pool, ptr);
478487
was_called_from_umfPool = 0;
488+
was_called_from_malloc_usable_size = 0;
479489
return size;
480490
}
481491

482492
#ifndef _WIN32
483-
if (Size_threshold_value) {
493+
if (!was_called_from_malloc_usable_size && Size_threshold_value) {
484494
return System_malloc_usable_size(ptr);
485495
}
486496
#endif /* _WIN32 */

0 commit comments

Comments
 (0)