Skip to content

Commit a4fced6

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 <[email protected]>
1 parent 1dd43b2 commit a4fced6

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
/*****************************************************************************/
@@ -455,15 +462,18 @@ size_t malloc_usable_size(void *ptr) {
455462
return 0; // unsupported in case of the ba_leak allocator
456463
}
457464

458-
if (Proxy_pool && (umfPoolByPtr(ptr) == Proxy_pool)) {
465+
if (!was_called_from_malloc_usable_size && Proxy_pool &&
466+
(umfPoolByPtr(ptr) == Proxy_pool)) {
467+
was_called_from_malloc_usable_size = 1;
459468
was_called_from_umfPool = 1;
460469
size_t size = umfPoolMallocUsableSize(Proxy_pool, ptr);
461470
was_called_from_umfPool = 0;
471+
was_called_from_malloc_usable_size = 0;
462472
return size;
463473
}
464474

465475
#ifndef _WIN32
466-
if (Size_threshold_value) {
476+
if (!was_called_from_malloc_usable_size && Size_threshold_value) {
467477
return System_malloc_usable_size(ptr);
468478
}
469479
#endif /* _WIN32 */

0 commit comments

Comments
 (0)