summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-04-17 20:27:33 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-04-17 20:27:33 +0000
commit2b51823f8d4ae1bd84a4e8d9d9d0ac0858f88bf1 (patch)
tree592ffb3c28c2a16639d999defae2f0449e1a6223
parent6c8a6700b898067a63b5044f5d21f7e67964a915 (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
-rw-r--r--win/configureVC80.vcproj2
-rw-r--r--win/inspircd_memory_functions.cpp15
2 files changed, 15 insertions, 2 deletions
diff --git a/win/configureVC80.vcproj b/win/configureVC80.vcproj
index 8b4399e6b..e46cad94e 100644
--- a/win/configureVC80.vcproj
+++ b/win/configureVC80.vcproj
@@ -128,7 +128,7 @@
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
+ Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
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);
+}