diff options
author | 2023-05-04 02:41:16 +1000 | |
---|---|---|
committer | 2023-05-04 02:41:16 +1000 | |
commit | a504bde3a7462b54fafd5cfc2f52e58d0f3218e1 (patch) | |
tree | 8b3108d572b1a0873a6cdbb4e8af1f17179545c3 /3rdparty/lzma/CPP/Common/NewHandler.cpp | |
parent | befb9bf4a8cfdb2b693a32e32535b5eac522c5d8 (diff) |
3rdparty/lzma: Updated to LZMA SDK version 22.01
Diffstat (limited to '3rdparty/lzma/CPP/Common/NewHandler.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/Common/NewHandler.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/3rdparty/lzma/CPP/Common/NewHandler.cpp b/3rdparty/lzma/CPP/Common/NewHandler.cpp index 522c2a75390..65ef41d4f5c 100644 --- a/3rdparty/lzma/CPP/Common/NewHandler.cpp +++ b/3rdparty/lzma/CPP/Common/NewHandler.cpp @@ -10,7 +10,7 @@ #ifndef DEBUG_MEMORY_LEAK -#ifdef _WIN32 +#ifdef _7ZIP_REDEFINE_OPERATOR_NEW /* void * my_new(size_t size) @@ -97,19 +97,33 @@ const int kDebugSize = 1000000; static void *a[kDebugSize]; static int index = 0; +static bool wasInit = false; +static CRITICAL_SECTION cs; + static int numAllocs = 0; void * __cdecl operator new(size_t size) { + if (!wasInit) + { + InitializeCriticalSection(&cs); + wasInit = true; + } + EnterCriticalSection(&cs); + numAllocs++; + int loc = numAllocs; void *p = HeapAlloc(GetProcessHeap(), 0, size); + /* if (index < kDebugSize) { a[index] = p; index++; } + */ + printf("Alloc %6d, size = %8u\n", loc, (unsigned)size); + LeaveCriticalSection(&cs); if (p == 0) throw CNewException(); - printf("Alloc %6d, size = %8u\n", numAllocs, (unsigned)size); return p; } @@ -123,6 +137,7 @@ public: } ~CC() { + printf("\nDestructor: %d\n", numAllocs); for (int i = 0; i < kDebugSize; i++) if (a[i] != 0) return; @@ -134,6 +149,7 @@ void __cdecl operator delete(void *p) { if (p == 0) return; + EnterCriticalSection(&cs); /* for (int i = 0; i < index; i++) if (a[i] == p) @@ -142,6 +158,7 @@ void __cdecl operator delete(void *p) HeapFree(GetProcessHeap(), 0, p); numAllocs--; printf("Free %d\n", numAllocs); + LeaveCriticalSection(&cs); } #endif |