Skip to content

Commit a32d757

Browse files
authored
Do not initialize pointers to original functions in (libc_)free (#1956)
Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent 3ebfedd commit a32d757

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/tbbmalloc_proxy/proxy.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Copyright (c) 2005-2024 Intel Corporation
2+
Copyright (c) 2005-2026 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -196,7 +197,10 @@ TBBMALLOCPROXY_EXPORT void *PREFIX(calloc)(ZONE_ARG size_t num, size_t size) __T
196197

197198
TBBMALLOCPROXY_EXPORT void PREFIX(free)(ZONE_ARG void *object) __THROW
198199
{
199-
InitOrigPointers();
200+
// InitOrigPointers() must NOT be called here,
201+
// because it may cause the infinite recursion:
202+
// free() -> InitOrigPointers() -> dlsym() -> free()
203+
// (see issue #1907)
200204
__TBB_malloc_safer_free(object, (void (*)(void*))orig_free);
201205
}
202206

@@ -293,7 +297,10 @@ TBBMALLOCPROXY_EXPORT void *__libc_valloc(size_t size) __TBB_ALIAS_ATTR_COPY(val
293297
// call original __libc_* to support naive replacement of free via __libc_free etc
294298
TBBMALLOCPROXY_EXPORT void __libc_free(void *ptr)
295299
{
296-
InitOrigPointers();
300+
// InitOrigPointers() must NOT be called here,
301+
// because it may cause the infinite recursion:
302+
// libc_free() -> InitOrigPointers() -> dlsym() -> libc_free()
303+
// (see issue #1907)
297304
__TBB_malloc_safer_free(ptr, (void (*)(void*))orig_libc_free);
298305
}
299306

0 commit comments

Comments
 (0)