diff options
| author | 2008-04-17 20:27:33 +0000 | |
|---|---|---|
| committer | 2008-04-17 20:27:33 +0000 | |
| commit | 2b51823f8d4ae1bd84a4e8d9d9d0ac0858f88bf1 (patch) | |
| tree | 592ffb3c28c2a16639d999defae2f0449e1a6223 /win/inspircd_memory_functions.cpp | |
| parent | Add todo note (diff) | |
Add operator new[] and delete[], otherwise we can and will get crashes on using a C++ allocated array outside the place where its allocated. Thanks for finding this (indirectly) GreenReaper :)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9532 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'win/inspircd_memory_functions.cpp')
| -rw-r--r-- | win/inspircd_memory_functions.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/win/inspircd_memory_functions.cpp b/win/inspircd_memory_functions.cpp index 1f269e000..c48c833dc 100644 --- a/win/inspircd_memory_functions.cpp +++ b/win/inspircd_memory_functions.cpp @@ -28,7 +28,7 @@ void * ::operator new(size_t iSize) { - void* ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iSize); /* zero memory for unix compatibility */ + void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* zero memory for unix compatibility */ /* This is the correct behaviour according to C++ standards for out of memory, * not returning null -- Brain */ @@ -42,3 +42,16 @@ void ::operator delete(void * ptr) { HeapFree(GetProcessHeap(), 0, ptr); } + +void * operator new[] (size_t iSize) { + void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* Why were we initializing the memory to zeros here? This is just a waste of cpu! */ + if (!ptr) + throw std::bad_alloc(); + else + return ptr; +} + +void operator delete[] (void* ptr) +{ + HeapFree(GetProcessHeap(), 0, ptr); +} |
