From 915693ac39a668830d00add1cc328974409b89f3 Mon Sep 17 00:00:00 2001 From: JW Date: Sun, 11 Apr 2021 16:40:24 -0700 Subject: [PATCH] Use tracy_malloc rather than 'new' in ProfilerThreadDataKey This codepath, involving a workaround for GCC < 8.4, called 'new' and 'delete' directly, which could cause infinite recursion when user-provided versions of those functions were themselves using Tracy functionality. Now, this codepath uses Tracy's internal allocator. See issues #194, #196 --- client/TracyProfiler.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index bcf43942..e8e98c14 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1069,7 +1069,9 @@ public: void* p = pthread_getspecific(m_key); if (!p) { - p = new ProfilerThreadData(GetProfilerData()); + RPMallocInit init; + p = (ProfilerThreadData*)tracy_malloc( sizeof( ProfilerThreadData ) ); + new (p) ProfilerThreadData(GetProfilerData()); pthread_setspecific(m_key, p); } return *static_cast(p); @@ -1079,7 +1081,8 @@ private: static void sDestructor(void* p) { - delete static_cast(p); + ((ProfilerThreadData*)p)->~ProfilerThreadData(); + tracy_free(p); } };