Skip to content

Commit c73a79a

Browse files
committed
[GEN][ZH] Fix undefined behavior with MemoryPoolObject::deleteInstance (#870)
1 parent e99e0c0 commit c73a79a

File tree

282 files changed

+1017
-1009
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+1017
-1009
lines changed

Core/GameEngine/Source/Common/System/XferSave.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ XferSave::~XferSave( void )
9191
{
9292

9393
next = m_blockStack->next;
94-
m_blockStack->deleteInstance();
94+
MemoryPoolObject::deleteInstance(m_blockStack);
9595
m_blockStack = next;
9696

9797
} // end while
@@ -247,7 +247,7 @@ void XferSave::endBlock( void )
247247
fseek( m_fileFP, currentFilePos, SEEK_SET );
248248

249249
// delete the block data as it's all used up now
250-
top->deleteInstance();
250+
MemoryPoolObject::deleteInstance(top);
251251

252252
} // end endBlock
253253

Generals/Code/GameEngine/Include/Common/GameMemory.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,13 @@ class MemoryPoolObject
756756

757757
public:
758758

759-
void deleteInstance()
759+
static void deleteInstance(MemoryPoolObject* mpo)
760760
{
761-
if (this)
761+
if (mpo)
762762
{
763-
MemoryPool *pool = this->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl
764-
this->~MemoryPoolObject(); // it's virtual, so the right one will be called.
765-
pool->freeBlock((void *)this);
763+
MemoryPool *pool = mpo->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl
764+
mpo->~MemoryPoolObject(); // it's virtual, so the right one will be called.
765+
pool->freeBlock((void *)mpo);
766766
}
767767
}
768768
};
@@ -906,7 +906,7 @@ class MemoryPoolObjectHolder
906906
MemoryPoolObjectHolder(MemoryPoolObject *mpo = NULL) : m_mpo(mpo) { }
907907
void hold(MemoryPoolObject *mpo) { DEBUG_ASSERTCRASH(!m_mpo, ("already holding")); m_mpo = mpo; }
908908
void release() { m_mpo = NULL; }
909-
~MemoryPoolObjectHolder() { m_mpo->deleteInstance(); }
909+
~MemoryPoolObjectHolder() { MemoryPoolObject::deleteInstance(m_mpo); }
910910
};
911911

912912

@@ -919,7 +919,11 @@ class MemoryPoolObjectHolder
919919
you really want by including this macro
920920
*/
921921
#define MEMORY_POOL_DELETEINSTANCE_VISIBILITY(ARGVIS)\
922-
ARGVIS: void deleteInstance() { MemoryPoolObject::deleteInstance(); } public:
922+
ARGVIS: \
923+
static void deleteInstance(MemoryPoolObject* object) { \
924+
MemoryPoolObject::deleteInstance(object); \
925+
} \
926+
public:
923927

924928

925929
#define EMPTY_DTOR(CLASS) inline CLASS::~CLASS() { }

Generals/Code/GameEngine/Include/Common/GameMemoryNull.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ class MemoryPoolObject
108108

109109
public:
110110

111-
void deleteInstance()
111+
static void deleteInstance(MemoryPoolObject* mpo)
112112
{
113-
delete this;
113+
delete mpo;
114114
}
115115
};
116116

Generals/Code/GameEngine/Include/Common/Overridable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Overridable : public MemoryPoolObject
108108
{
109109
if ( m_isOverride )
110110
{
111-
deleteInstance();
111+
MemoryPoolObject::deleteInstance(this);
112112
return NULL;
113113
}
114114
else if ( m_nextOverride )
@@ -123,7 +123,7 @@ class Overridable : public MemoryPoolObject
123123
__inline Overridable::~Overridable()
124124
{
125125
if (m_nextOverride)
126-
m_nextOverride->deleteInstance();
126+
MemoryPoolObject::deleteInstance(m_nextOverride);
127127
}
128128

129129

Generals/Code/GameEngine/Include/Common/ThingTemplate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class AudioArray
159159
{
160160
for (Int i = 0; i < TTAUDIO_COUNT; ++i)
161161
if (m_audio[i])
162-
m_audio[i]->deleteInstance();
162+
MemoryPoolObject::deleteInstance(m_audio[i]);
163163
}
164164

165165
AudioArray(const AudioArray& that)

Generals/Code/GameEngine/Include/GameLogic/Object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class Object : public Thing, public Snapshot
386386
Bool isInList(Object **pListHead) const;
387387

388388
// this is intended for use ONLY by GameLogic.
389-
void friend_deleteInstance() { deleteInstance(); }
389+
static void friend_deleteInstance(MemoryPoolObject* object) { MemoryPoolObject::deleteInstance(object); }
390390

391391
/// cache the partition module (should be called only by PartitionData)
392392
void friend_setPartitionData(PartitionData *pd) { m_partitionData = pd; }

Generals/Code/GameEngine/Include/GameLogic/ObjectIter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum IterOrderType CPP_11(: Int)
6767
{
6868
// do something with other
6969
}
70-
iter->deleteInstance(); // you own it, so you must delete it
70+
MemoryPoolObject::deleteInstance(iter); // you own it, so you must delete it
7171
7272
note that the iterator is required to deal intelligently with deleted objects;
7373
in particular, next() will check if an obj has been killed and simply skip it.

Generals/Code/GameEngine/Source/Common/Audio/GameAudio.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ AudioManager::~AudioManager()
188188
for (it = m_allAudioEventInfo.begin(); it != m_allAudioEventInfo.end(); ++it) {
189189
AudioEventInfo *eventInfo = (*it).second;
190190
if (eventInfo) {
191-
eventInfo->deleteInstance();
191+
MemoryPoolObject::deleteInstance(eventInfo);
192192
eventInfo = NULL;
193193
}
194194
}
@@ -811,7 +811,7 @@ AudioRequest *AudioManager::allocateAudioRequest( Bool useAudioEvent )
811811
void AudioManager::releaseAudioRequest( AudioRequest *requestToRelease )
812812
{
813813
if (requestToRelease) {
814-
requestToRelease->deleteInstance();
814+
MemoryPoolObject::deleteInstance(requestToRelease);
815815
}
816816
}
817817

@@ -894,7 +894,7 @@ void AudioManager::removeLevelSpecificAudioEventInfos(void)
894894

895895
if ( it->second->isLevelSpecific() )
896896
{
897-
it->second->deleteInstance();
897+
MemoryPoolObject::deleteInstance(it->second);
898898
m_allAudioEventInfo.erase( it );
899899
}
900900

Generals/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ void GameEngine::reset( void )
536536
if(background)
537537
{
538538
background->destroyWindows();
539-
background->deleteInstance();
539+
MemoryPoolObject::deleteInstance(background);
540540
background = NULL;
541541
}
542542
}

Generals/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ GlobalData::~GlobalData( void )
10611061
DEBUG_ASSERTCRASH( TheWritableGlobalData->m_next == NULL, ("~GlobalData: theOriginal is not original\n") );
10621062

10631063
if (m_weaponBonusSet)
1064-
m_weaponBonusSet->deleteInstance();
1064+
MemoryPoolObject::deleteInstance(m_weaponBonusSet);
10651065

10661066
if( m_theOriginal == this ) {
10671067
m_theOriginal = NULL;

0 commit comments

Comments
 (0)