Skip to content

Commit bb39cc7

Browse files
authored
refactor: Remove superfluous null tests before calls to free() (#1562)
1 parent 4f06c9b commit bb39cc7

File tree

13 files changed

+36
-62
lines changed

13 files changed

+36
-62
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ Font3DDataClass::Font3DDataClass( const char *filename )
7171
***********************************************************************************************/
7272
Font3DDataClass::~Font3DDataClass(void)
7373
{
74-
if (Name != NULL) {
75-
free(Name);
76-
Name = NULL;
77-
}
74+
free(Name);
75+
Name = NULL;
7876

7977
REF_PTR_RELEASE(Texture);
8078
}

Core/Libraries/Source/WWVegas/WWAudio/Utils.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@
5858
pobject = NULL; \
5959
} \
6060

61-
#define SAFE_FREE(pobject) \
62-
if (pobject) { \
63-
::free (pobject); \
64-
pobject = NULL; \
65-
} \
61+
#define SAFE_FREE(pobject) { ::free (pobject); pobject = NULL; }
6662

6763

6864
/////////////////////////////////////////////////////////////////////////////

Core/Libraries/Source/WWVegas/WWLib/rcfile.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ ResourceFileClass::ResourceFileClass(HMODULE hmodule, char const *filename) :
6565

6666
ResourceFileClass::~ResourceFileClass(void)
6767
{
68-
if (ResourceName)
69-
free(ResourceName);
68+
free(ResourceName);
7069
}
7170

7271
char const * ResourceFileClass::Set_Name(char const *filename)
7372
{
74-
if (ResourceName) {
75-
free(ResourceName);
76-
ResourceName = NULL;
77-
}
73+
free(ResourceName);
74+
ResourceName = NULL;
75+
7876
if (filename) {
7977
ResourceName = strdup(filename);
8078
}

Core/Tools/Autorun/Locale_API.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,8 @@ void Locale_Restore ( void )
300300
LOCALE_freetable();
301301
LOCALE_restore();
302302
#else
303-
if( LocaleFile ) {
304-
free( LocaleFile );
305-
LocaleFile = NULL;
306-
}
303+
free( LocaleFile );
304+
LocaleFile = NULL;
307305
#endif
308306
}
309307

Generals/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,8 +1724,8 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
17241724
{
17251725
if( cells[j].cellType == LISTBOX_TEXT && cells[j].data )
17261726
TheDisplayStringManager->freeDisplayString((DisplayString *) cells[j].data );
1727-
// if (cells[i].userData)
1728-
// free(cells[i].userData);
1727+
1728+
// free(cells[i].userData);
17291729
cells[j].data = NULL;
17301730
cells[j].userData = NULL;
17311731
cells[j].color = 0;
@@ -1957,8 +1957,7 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
19571957
TheDisplayStringManager->freeDisplayString((DisplayString *) cells[j].data );
19581958
}
19591959
}
1960-
// if ( cells[j].userData )
1961-
// free(cells[j].userData);
1960+
// free(cells[j].userData);
19621961

19631962
// Null out the data pointers so they're not destroyed when we free up this listdata
19641963
cells[j].userData = NULL;
@@ -2546,8 +2545,7 @@ void GadgetListBoxSetListLength( GameWindow *listbox, Int newLength )
25462545
TheDisplayStringManager->freeDisplayString((DisplayString *) cells[j].data );
25472546
}
25482547
}
2549-
// if ( cells[j].userData )
2550-
// free(cells[j].userData);
2548+
// free(cells[j].userData);
25512549
}
25522550
}
25532551
if (i >= newLength) {

Generals/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,10 +1971,8 @@ void ConnectionManager::parseUserList(const GameInfo *game)
19711971
return;
19721972
}
19731973
1974-
if (list != NULL) {
1975-
free(list); // from the strdup above.
1976-
list = NULL;
1977-
}
1974+
free(list); // from the strdup above.
1975+
list = NULL;
19781976
*/
19791977
}
19801978

Generals/Code/GameEngine/Source/GameNetwork/GameInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)
14011401
break;
14021402
}
14031403
}
1404-
if(freeMe)
1404+
14051405
free(freeMe);
14061406
}
14071407
else
@@ -1410,8 +1410,8 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)
14101410
break;
14111411
}
14121412
}
1413-
if( buf )
1414-
free(buf);
1413+
1414+
free(buf);
14151415

14161416
//DEBUG_LOG(("Options were ok == %d", optionsOk));
14171417
if (optionsOk && sawMap && sawMapCRC && sawMapSize && sawSeed && sawSlotlist && sawCRC)

Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,11 @@ HLodDefClass::~HLodDefClass(void)
337337
*=============================================================================================*/
338338
void HLodDefClass::Free(void)
339339
{
340-
if (Name) {
341-
::free(Name);
342-
Name = NULL;
343-
}
340+
::free(Name);
341+
Name = NULL;
344342

345-
if (HierarchyTreeName) {
346-
::free(HierarchyTreeName);
347-
HierarchyTreeName = NULL;
348-
}
343+
::free(HierarchyTreeName);
344+
HierarchyTreeName = NULL;
349345

350346
if (Lod) {
351347
delete[] Lod;

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,8 +1724,8 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
17241724
{
17251725
if( cells[j].cellType == LISTBOX_TEXT && cells[j].data )
17261726
TheDisplayStringManager->freeDisplayString((DisplayString *) cells[j].data );
1727-
// if (cells[i].userData)
1728-
// free(cells[i].userData);
1727+
1728+
// free(cells[i].userData);
17291729
cells[j].data = NULL;
17301730
cells[j].userData = NULL;
17311731
cells[j].color = 0;
@@ -1957,8 +1957,7 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
19571957
TheDisplayStringManager->freeDisplayString((DisplayString *) cells[j].data );
19581958
}
19591959
}
1960-
// if ( cells[j].userData )
1961-
// free(cells[j].userData);
1960+
// free(cells[j].userData);
19621961

19631962
// Null out the data pointers so they're not destroyed when we free up this listdata
19641963
cells[j].userData = NULL;
@@ -2546,8 +2545,7 @@ void GadgetListBoxSetListLength( GameWindow *listbox, Int newLength )
25462545
TheDisplayStringManager->freeDisplayString((DisplayString *) cells[j].data );
25472546
}
25482547
}
2549-
// if ( cells[j].userData )
2550-
// free(cells[j].userData);
2548+
// free(cells[j].userData);
25512549
}
25522550
}
25532551
if (i >= newLength) {

GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,10 +1957,8 @@ void ConnectionManager::parseUserList(const GameInfo *game)
19571957
return;
19581958
}
19591959
1960-
if (list != NULL) {
1961-
free(list); // from the strdup above.
1962-
list = NULL;
1963-
}
1960+
free(list); // from the strdup above.
1961+
list = NULL;
19641962
*/
19651963
}
19661964

0 commit comments

Comments
 (0)