diff --git a/mp/src/game/client/c_baseentity.cpp b/mp/src/game/client/c_baseentity.cpp index 338f986c1e..2e9c9b3a92 100644 --- a/mp/src/game/client/c_baseentity.cpp +++ b/mp/src/game/client/c_baseentity.cpp @@ -3803,7 +3803,11 @@ void *C_BaseEntity::operator new( size_t stAllocateBlock ) { Assert( stAllocateBlock != 0 ); MEM_ALLOC_CREDIT(); +#if !defined(NO_MALLOC_OVERRIDE) void *pMem = MemAlloc_Alloc( stAllocateBlock ); +#else + void* pMem = malloc(stAllocateBlock); +#endif memset( pMem, 0, stAllocateBlock ); return pMem; } @@ -3812,7 +3816,11 @@ void *C_BaseEntity::operator new[]( size_t stAllocateBlock ) { Assert( stAllocateBlock != 0 ); MEM_ALLOC_CREDIT(); +#if !defined(NO_MALLOC_OVERRIDE) void *pMem = MemAlloc_Alloc( stAllocateBlock ); +#else + void* pMem = malloc(stAllocateBlock); +#endif memset( pMem, 0, stAllocateBlock ); return pMem; } @@ -3820,7 +3828,11 @@ void *C_BaseEntity::operator new[]( size_t stAllocateBlock ) void *C_BaseEntity::operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine ) { Assert( stAllocateBlock != 0 ); +#if !defined(NO_MALLOC_OVERRIDE) void *pMem = MemAlloc_Alloc( stAllocateBlock, pFileName, nLine ); +#else + void* pMem = malloc(stAllocateBlock); +#endif memset( pMem, 0, stAllocateBlock ); return pMem; } @@ -3828,7 +3840,11 @@ void *C_BaseEntity::operator new( size_t stAllocateBlock, int nBlockUse, const c void *C_BaseEntity::operator new[]( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine ) { Assert( stAllocateBlock != 0 ); +#if !defined(NO_MALLOC_OVERRIDE) void *pMem = MemAlloc_Alloc( stAllocateBlock, pFileName, nLine ); +#else + void* pMem = malloc(stAllocateBlock); +#endif memset( pMem, 0, stAllocateBlock ); return pMem; } @@ -3841,7 +3857,11 @@ void *C_BaseEntity::operator new[]( size_t stAllocateBlock, int nBlockUse, const void C_BaseEntity::operator delete( void *pMem ) { // get the engine to free the memory +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_Free( pMem ); +#else + free(pMem); +#endif } #include "tier0/memdbgon.h" @@ -4751,7 +4771,7 @@ C_BaseEntity *C_BaseEntity::Instance( int iEnt ) #ifdef WIN32 #pragma warning( push ) -#include +#include #pragma warning( pop ) #endif diff --git a/mp/src/game/client/client_base.vpc b/mp/src/game/client/client_base.vpc index b1e5ae532a..749cf215f0 100644 --- a/mp/src/game/client/client_base.vpc +++ b/mp/src/game/client/client_base.vpc @@ -52,7 +52,7 @@ $Configuration $Compiler { $AdditionalIncludeDirectories ".\;$BASE;$SRCDIR\vgui2\include;$SRCDIR\vgui2\controls;$SRCDIR\game\shared;.\game_controls;$SRCDIR\thirdparty\sixensesdk\include" - $PreprocessorDefinitions "$BASE;NO_STRING_T;CLIENT_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" + $PreprocessorDefinitions "$BASE;NO_STRING_T;CLIENT_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;NO_MALLOC_OVERRIDE;REMEMBER_ALLOC_SIZE_FOR_VALGRIND" $PreprocessorDefinitions "$BASE;fopen=dont_use_fopen" [$WIN32] $PreprocessorDefinitions "$BASE;USE_WEBM_FOR_REPLAY;" [$LINUXALL] $PreprocessorDefinitions "$BASE;CURL_STATICLIB" [$WIN32 && $BUILD_REPLAY] diff --git a/mp/src/game/client/detailobjectsystem.cpp b/mp/src/game/client/detailobjectsystem.cpp index 3e211bb036..047302e2f6 100644 --- a/mp/src/game/client/detailobjectsystem.cpp +++ b/mp/src/game/client/detailobjectsystem.cpp @@ -1408,17 +1408,29 @@ void CDetailObjectSystem::FreeSortBuffers( void ) { if ( m_pSortInfo ) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( m_pSortInfo ); +#else + delete[] m_pSortInfo; +#endif m_pSortInfo = NULL; } if ( m_pFastSortInfo ) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( m_pFastSortInfo ); +#else + delete[] m_pFastSortInfo; +#endif m_pFastSortInfo = NULL; } if ( m_pBuildoutBuffer ) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( m_pBuildoutBuffer ); +#else + delete[] m_pBuildoutBuffer; +#endif m_pBuildoutBuffer = NULL; } } @@ -1427,7 +1439,11 @@ CDetailObjectSystem::~CDetailObjectSystem() { if ( m_pFastSpriteData ) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( m_pFastSpriteData ); +#else + delete[] m_pFastSpriteData; +#endif m_pFastSpriteData = NULL; } FreeSortBuffers(); @@ -1543,7 +1559,11 @@ void CDetailObjectSystem::LevelShutdownPreEntity() m_DetailSpriteMaterial.Shutdown(); if ( m_pFastSpriteData ) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( m_pFastSpriteData ); +#else + delete[] m_pFastSpriteData; +#endif m_pFastSpriteData = NULL; } FreeSortBuffers(); @@ -1735,28 +1755,48 @@ void CDetailObjectSystem::UnserializeModels( CUtlBuffer& buf ) if ( nMaxOldInLeaf ) { +#if !defined(NO_MALLOC_OVERRIDE) m_pSortInfo = reinterpret_cast ( MemAlloc_AllocAligned( (3 + nMaxOldInLeaf ) * sizeof( SortInfo_t ), sizeof( fltx4 ) ) ); +#else + m_pSortInfo = reinterpret_cast ( + ::operator new((3 + nMaxOldInLeaf) * sizeof(SortInfo_t), std::nothrow)); +#endif } if ( nMaxFastInLeaf ) { +#if !defined(NO_MALLOC_OVERRIDE) m_pFastSortInfo = reinterpret_cast ( MemAlloc_AllocAligned( (3 + nMaxFastInLeaf ) * sizeof( SortInfo_t ), sizeof( fltx4 ) ) ); +#else + m_pFastSortInfo = reinterpret_cast ( + ::operator new((3 + nMaxFastInLeaf) * sizeof(SortInfo_t), std::nothrow)); +#endif +#if !defined(NO_MALLOC_OVERRIDE) m_pBuildoutBuffer = reinterpret_cast ( MemAlloc_AllocAligned( ( 1 + nMaxFastInLeaf / 4 ) * sizeof( FastSpriteQuadBuildoutBufferX4_t ), sizeof( fltx4 ) ) ); +#else + m_pBuildoutBuffer = reinterpret_cast ( + ::operator new((1 + nMaxFastInLeaf / 4) * sizeof(FastSpriteQuadBuildoutBufferX4_t), std::nothrow)); +#endif } if ( nNumFastSpritesToAllocate ) { Assert( ( nNumFastSpritesToAllocate & 3 ) == 0 ); Assert( ! m_pFastSpriteData ); // wtf? didn't free? +#if !defined(NO_MALLOC_OVERRIDE) m_pFastSpriteData = reinterpret_cast ( MemAlloc_AllocAligned( ( nNumFastSpritesToAllocate >> 2 ) * sizeof( FastSpriteX4_t ), sizeof( fltx4 ) ) ); +#else + m_pFastSpriteData = reinterpret_cast ( + ::operator new((nNumFastSpritesToAllocate >> 2) * sizeof(FastSpriteX4_t), std::nothrow)); +#endif } m_DetailObjects.EnsureCapacity( nNumOldStyleObjects ); diff --git a/mp/src/game/client/hudelement.h b/mp/src/game/client/hudelement.h index b903de5d45..0c533d6c66 100644 --- a/mp/src/game/client/hudelement.h +++ b/mp/src/game/client/hudelement.h @@ -74,7 +74,11 @@ class CHudElement : public CGameEventListener void* operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine ) { Assert( stAllocateBlock != 0 ); +#if !defined(NO_MALLOC_OVERRIDE) void *pMem = MemAlloc_Alloc( stAllocateBlock, pFileName, nLine ); +#else + void* pMem = malloc(stAllocateBlock); +#endif memset( pMem, 0, stAllocateBlock ); return pMem; } diff --git a/mp/src/game/server/ai_component.h b/mp/src/game/server/ai_component.h index 2385d61b82..3804b1f04e 100644 --- a/mp/src/game/server/ai_component.h +++ b/mp/src/game/server/ai_component.h @@ -124,7 +124,11 @@ class CAI_Component void *operator new( size_t nBytes ) { MEM_ALLOC_CREDIT(); +#if !defined(NO_MALLOC_OVERRIDE) void *pResult = MemAlloc_Alloc( nBytes ); +#else + void* pResult = malloc(nBytes); +#endif memset( pResult, 0, nBytes ); return pResult; }; @@ -132,7 +136,11 @@ class CAI_Component void *operator new( size_t nBytes, int nBlockUse, const char *pFileName, int nLine ) { MEM_ALLOC_CREDIT(); +#if !defined(NO_MALLOC_OVERRIDE) void *pResult = MemAlloc_Alloc( nBytes, pFileName, nLine ); +#else + void* pResult = malloc(nBytes); +#endif memset( pResult, 0, nBytes ); return pResult; } diff --git a/mp/src/game/server/server_base.vpc b/mp/src/game/server/server_base.vpc index f1c3c83561..5e65233db7 100644 --- a/mp/src/game/server/server_base.vpc +++ b/mp/src/game/server/server_base.vpc @@ -52,7 +52,7 @@ $Configuration $Compiler { $AdditionalIncludeDirectories "$BASE;.\;$SRCDIR\game\shared;$SRCDIR\utils\common;$SRCDIR\game\shared\econ;$SRCDIR\game\server\NextBot" - $PreprocessorDefinitions "$BASE;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" + $PreprocessorDefinitions "$BASE;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;NO_MALLOC_OVERRIDE;REMEMBER_ALLOC_SIZE_FOR_VALGRIND" $PreprocessorDefinitions "$BASE;SWDS" [$POSIX] $PreprocessorDefinitions "$BASE;fopen=dont_use_fopen" [$WINDOWS||$X360] $Create/UsePrecompiledHeader "Use Precompiled Header (/Yu)" diff --git a/mp/src/public/tier0/tslist.h b/mp/src/public/tier0/tslist.h index d6610e0c5b..39588b7571 100644 --- a/mp/src/public/tier0/tslist.h +++ b/mp/src/public/tier0/tslist.h @@ -134,24 +134,40 @@ class CTSListBase // override new/delete so we can guarantee 8-byte aligned allocs static void * operator new( size_t size ) { +#if !defined(NO_MALLOC_OVERRIDE) CTSListBase *pNode = (CTSListBase *)MemAlloc_AllocAligned( size, TSLIST_HEAD_ALIGNMENT, __FILE__, __LINE__ ); +#else + CTSListBase* pNode = (CTSListBase*)malloc(size); +#endif return pNode; } static void * operator new( size_t size, int nBlockUse, const char *pFileName, int nLine ) { +#if !defined(NO_MALLOC_OVERRIDE) CTSListBase *pNode = (CTSListBase *)MemAlloc_AllocAligned( size, TSLIST_HEAD_ALIGNMENT, pFileName, nLine ); +#else + CTSListBase* pNode = (CTSListBase*)malloc(size); +#endif return pNode; } static void operator delete( void *p) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( p ); +#else + free(p); +#endif } static void operator delete( void *p, int nBlockUse, const char *pFileName, int nLine ) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( p ); +#else + free(p); +#endif } private: @@ -417,7 +433,11 @@ class TSLIST_HEAD_ALIGN CTSList : public CTSListBase // override new/delete so we can guarantee 8-byte aligned allocs static void * operator new( size_t size ) { +#if !defined(NO_MALLOC_OVERRIDE) Node_t *pNode = (Node_t *)MemAlloc_AllocAligned( size, TSLIST_NODE_ALIGNMENT, __FILE__, __LINE__ ); +#else + Node_t* pNode = (Node_t*)malloc(size); +#endif return pNode; } @@ -430,7 +450,11 @@ class TSLIST_HEAD_ALIGN CTSList : public CTSListBase static void operator delete( void *p) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( p ); +#else + free(p); +#endif } static void operator delete( void *p, int nBlockUse, const char *pFileName, int nLine ) { @@ -649,19 +673,31 @@ class TSLIST_HEAD_ALIGN CTSQueue // override new/delete so we can guarantee 8-byte aligned allocs static void * operator new( size_t size ) { +#if !defined(NO_MALLOC_OVERRIDE) Node_t *pNode = (Node_t *)MemAlloc_AllocAligned( size, TSLIST_HEAD_ALIGNMENT, __FILE__, __LINE__ ); +#else + Node_t* pNode = (Node_t*)malloc(size); +#endif return pNode; } static void * operator new( size_t size, int nBlockUse, const char *pFileName, int nLine ) { +#if !defined(NO_MALLOC_OVERRIDE) Node_t *pNode = (Node_t *)MemAlloc_AllocAligned( size, TSLIST_HEAD_ALIGNMENT, pFileName, nLine ); +#else + Node_t* pNode = (Node_t*)malloc(size); +#endif return pNode; } static void operator delete( void *p) { +#if !defined(NO_MALLOC_OVERRIDE) MemAlloc_FreeAligned( p ); +#else + free(p); +#endif } static void operator delete( void *p, int nBlockUse, const char *pFileName, int nLine )