Skip to content

Commit 06c6b3b

Browse files
authored
refactor: Remove superfluous null tests before calls to delete, delete[] (#1560)
1 parent 6bc424c commit 06c6b3b

File tree

258 files changed

+1544
-2750
lines changed

Some content is hidden

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

258 files changed

+1544
-2750
lines changed

Core/GameEngine/Source/Common/Audio/GameAudio.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ AudioManager::~AudioManager()
203203
delete m_audioSettings;
204204
m_audioSettings = NULL;
205205

206-
if (m_savedValues)
207-
delete [] m_savedValues;
206+
delete [] m_savedValues;
208207
}
209208

210209
//-------------------------------------------------------------------------------------------------
@@ -1085,11 +1084,8 @@ AudioHandle AudioManager::allocateNewHandle( void )
10851084
//-------------------------------------------------------------------------------------------------
10861085
void AudioManager::releaseAudioEventRTS( AudioEventRTS *&eventToRelease )
10871086
{
1088-
if( eventToRelease )
1089-
{
1090-
delete eventToRelease;
1091-
eventToRelease = NULL;
1092-
}
1087+
delete eventToRelease;
1088+
eventToRelease = NULL;
10931089
}
10941090

10951091
//-------------------------------------------------------------------------------------------------

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ ArchiveFileSystem::~ArchiveFileSystem()
110110
ArchiveFileMap::iterator iter = m_archiveFileMap.begin();
111111
while (iter != m_archiveFileMap.end()) {
112112
ArchiveFile *file = iter->second;
113-
if (file != NULL) {
114-
delete file;
115-
file = NULL;
116-
}
113+
delete file;
117114
iter++;
118115
}
119116
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ Bool RAMFile::openFromArchive(File *archiveFile, const AsciiString& filename, In
216216
return FALSE;
217217
}
218218

219-
if (m_data != NULL) {
220-
delete[] m_data;
221-
m_data = NULL;
222-
}
219+
delete[] m_data;
223220
m_data = MSGNEW("RAMFILE") Char [size]; // pool[]ify
224221
m_size = size;
225222

Core/GameEngine/Source/GameClient/GUI/WindowVideoManager.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ WindowVideo::~WindowVideo( void )
101101
m_videoBuffer = NULL;
102102

103103
if ( m_videoStream )
104+
{
104105
m_videoStream->close();
105-
m_videoStream = NULL;
106-
106+
m_videoStream = NULL;
107+
}
107108
}
108109

109110
void WindowVideo::init( GameWindow *win, AsciiString movieName,
@@ -140,8 +141,7 @@ WindowVideoManager::WindowVideoManager( void )
140141
while(it != m_playingVideos.end())
141142
{
142143
WindowVideo *winVid = it->second;
143-
if(winVid)
144-
delete winVid;
144+
delete winVid;
145145
it++;
146146
}
147147
m_playingVideos.clear();
@@ -157,8 +157,7 @@ WindowVideoManager::~WindowVideoManager( void )
157157
while(it != m_playingVideos.end())
158158
{
159159
WindowVideo *winVid = it->second;
160-
if(winVid)
161-
delete winVid;
160+
delete winVid;
162161
it++;
163162
}
164163
m_playingVideos.clear();
@@ -180,8 +179,7 @@ void WindowVideoManager::reset( void )
180179
while(it != m_playingVideos.end())
181180
{
182181
WindowVideo *winVid = it->second;
183-
if(winVid)
184-
delete winVid;
182+
delete winVid;
185183
it++;
186184
}
187185
m_playingVideos.clear();
@@ -277,8 +275,10 @@ void WindowVideoManager::playMovie( GameWindow *win, AsciiString movieName, Wind
277275
videoBuffer = NULL;
278276

279277
if ( videoStream )
278+
{
280279
videoStream->close();
281-
videoStream = NULL;
280+
videoStream = NULL;
281+
}
282282

283283
return;
284284
}
@@ -349,9 +349,7 @@ void WindowVideoManager::stopAndRemoveMovie( GameWindow *win )
349349
if(it != m_playingVideos.end())
350350
{
351351
WindowVideo *winVid = it->second;
352-
if(winVid)
353-
delete winVid;
354-
winVid = NULL;
352+
delete winVid;
355353
m_playingVideos.erase(it);
356354
}
357355
}

Core/Libraries/Source/WWVegas/WW3D2/aabtree.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,14 @@ AABTreeClass & AABTreeClass::operator = (const AABTreeClass & that)
211211
void AABTreeClass::Reset(void)
212212
{
213213
NodeCount = 0;
214-
if (Nodes) {
215-
delete[] Nodes;
216-
Nodes = NULL;
217-
}
214+
delete[] Nodes;
215+
Nodes = NULL;
216+
218217
PolyCount = 0;
219-
if (PolyIndices) {
220-
delete[] PolyIndices;
221-
PolyIndices = NULL;
222-
}
223-
if (Mesh) {
224-
Mesh = NULL;
225-
}
218+
delete[] PolyIndices;
219+
PolyIndices = NULL;
220+
221+
Mesh = NULL;
226222
}
227223

228224
/***********************************************************************************************

Core/Libraries/Source/WWVegas/WW3D2/agg_def.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ AggregateDefClass::Free_Subobject_List (void)
182182
// Delete all the stucture pointers contained in the subobject list
183183
for (int index = 0; index < m_SubobjectList.Count (); index ++) {
184184
W3dAggregateSubobjectStruct *pinfo = m_SubobjectList[index];
185-
if (pinfo) {
186-
delete pinfo;
187-
}
185+
delete pinfo;
188186
}
189187

190188
// Reset the lists contents
@@ -883,7 +881,7 @@ AggregateLoaderClass::Load_W3D (ChunkLoadClass &chunk_load)
883881

884882
// Error! Free the definition
885883
delete pdefinition;
886-
pdefinition = NULL;
884+
887885
} else {
888886

889887
// Success! Create a prototype from the definition

Core/Libraries/Source/WWVegas/WW3D2/decalsys.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,8 @@ MultiFixedPoolDecalSystemClass::MultiFixedPoolDecalSystemClass(const MultiFixedP
329329

330330
MultiFixedPoolDecalSystemClass::~MultiFixedPoolDecalSystemClass(void)
331331
{
332-
if (Pools) {
333-
delete [] Pools;
334-
Pools = 0;
335-
}
332+
delete [] Pools;
333+
Pools = NULL;
336334
}
337335

338336
// This clears the slot in addition to locking the generator, thus preventing any decal id
@@ -463,25 +461,21 @@ void MultiFixedPoolDecalSystemClass::LogicalDecalClass::Clear(uint32 decal_id)
463461
*/
464462

465463
MultiFixedPoolDecalSystemClass::LogicalDecalPoolClass::LogicalDecalPoolClass(void) :
466-
Array(0),
464+
Array(NULL),
467465
Size(0)
468466
{
469467
}
470468

471469
MultiFixedPoolDecalSystemClass::LogicalDecalPoolClass::~LogicalDecalPoolClass(void)
472470
{
473-
if (Array) {
474-
delete [] Array;
475-
Array = 0;
476-
}
471+
delete [] Array;
472+
Array = NULL;
477473
}
478474

479475
void MultiFixedPoolDecalSystemClass::LogicalDecalPoolClass::Initialize(uint32 size)
480476
{
481-
if (Array) {
482-
delete [] Array;
483-
Array = 0;
484-
}
477+
delete [] Array;
478+
Array = NULL;
485479

486480
Size = size;
487481
assert(Size);

Core/Libraries/Source/WWVegas/WW3D2/distlod.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,12 @@ DistLODDefClass::~DistLODDefClass(void)
242242
*=============================================================================================*/
243243
void DistLODDefClass::Free(void)
244244
{
245-
if (Name != NULL) {
246-
delete[] Name;
247-
Name = NULL;
248-
}
245+
delete[] Name;
246+
Name = NULL;
247+
249248
if (Lods != NULL) {
250249
for (int i=0; i<LodCount; i++) {
251-
if (Lods[i].Name != NULL) {
252-
delete[] Lods[i].Name;
253-
}
250+
delete[] Lods[i].Name;
254251
}
255252
delete[] Lods;
256253
Lods = NULL;

Core/Libraries/Source/WWVegas/WW3D2/dynamesh.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,9 @@ DynamicMeshModel::DynamicMeshModel(const DynamicMeshModel &src) :
104104

105105
DynamicMeshModel::~DynamicMeshModel(void)
106106
{
107-
if (MatDesc) {
108-
delete MatDesc;
109-
MatDesc = NULL;
110-
}
107+
delete MatDesc;
108+
MatDesc = NULL;
109+
111110
REF_PTR_RELEASE(MatInfo);
112111
}
113112

Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ NamedPivotMapClass::~NamedPivotMapClass(void)
6262

6363
NamedPivotMapClass::WeightInfoStruct & NamedPivotMapClass::WeightInfoStruct::operator = (WeightInfoStruct const &that)
6464
{
65-
if(Name) delete [] Name;
66-
assert(that.Name != 0);
65+
delete [] Name;
66+
assert(that.Name != NULL);
6767
Name = nstrdup(that.Name);
6868
Weight = that.Weight;
6969
return *this;

0 commit comments

Comments
 (0)