From c2c234cf5a46daf0d89d3ccea03e4538c0fdac1f Mon Sep 17 00:00:00 2001 From: Thales Sabino Date: Thu, 21 May 2020 14:26:29 +0100 Subject: [PATCH] Fix crash when running Tracy from DLLs Instantiating Tracy from within a DLL will tie its internal threads life-time to the DLL. Windows does not guarantee that threads will be alive after the main function. This has implications in the Profiler dtor since will try to perform some deallocations, however, _memory_deallocate_large will try to get the heap of the current thread which can be invalid at the point of shutdown causing a crash. Checking the pointer here will won't make TRACE_NO_EXIT work, but it will prevent the Profiler from crashing. --- client/tracy_rpmalloc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/client/tracy_rpmalloc.cpp b/client/tracy_rpmalloc.cpp index a2e2fd38..552543ec 100644 --- a/client/tracy_rpmalloc.cpp +++ b/client/tracy_rpmalloc.cpp @@ -1468,6 +1468,7 @@ _memory_deallocate_large(span_t* span) { //Investigate if it is better to defer large spans as well through span_cache_deferred, //possibly with some heuristics to pick either scheme at runtime per deallocation heap_t* heap = get_thread_heap(); + if (!heap) return; #if ENABLE_ADAPTIVE_THREAD_CACHE || ENABLE_STATISTICS size_t idx = span->span_count - 1; atomic_decr32(&span->heap->span_use[idx].current);