From c74c596ab77d6d3f07f3ac4b09a8efcfb0ca6fb0 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Fri, 28 Jan 2022 14:51:45 -0800 Subject: [PATCH] Implement operator delete on ThreadStressLog --- src/coreclr/inc/stresslog.h | 1 + src/coreclr/utilcode/stresslog.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/coreclr/inc/stresslog.h b/src/coreclr/inc/stresslog.h index 4ee3acaeb8bb6c..35381a17cbb310 100644 --- a/src/coreclr/inc/stresslog.h +++ b/src/coreclr/inc/stresslog.h @@ -740,6 +740,7 @@ class ThreadStressLog { #if defined(MEMORY_MAPPED_STRESSLOG) && !defined(STRESS_LOG_ANALYZER) void* __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT; + void __cdecl operator delete (void * chunk); #endif ~ThreadStressLog () diff --git a/src/coreclr/utilcode/stresslog.cpp b/src/coreclr/utilcode/stresslog.cpp index 5d13b2ec7695ca..0d6f4cd53c93f0 100644 --- a/src/coreclr/utilcode/stresslog.cpp +++ b/src/coreclr/utilcode/stresslog.cpp @@ -965,6 +965,19 @@ void* __cdecl ThreadStressLog::operator new(size_t n, const NoThrow&) NOEXCEPT return malloc(n); #endif //HOST_WINDOWS } + +void __cdecl ThreadStressLog::operator delete(void* p) +{ + if (StressLogChunk::s_memoryMapped) + return; // Giving up, we will just leak it instead of building a sophisticated allocator +#ifdef HOST_WINDOWS + _ASSERTE(StressLogChunk::s_LogChunkHeap); + HeapFree(StressLogChunk::s_LogChunkHeap, 0, p); +#else + free(p); +#endif //HOST_WINDOWS +} + #endif //MEMORY_MAPPED_STRESSLOG #endif // STRESS_LOG