Merge pull request #1673 from sphericalice/try-free-and-set-null

Use the TRY_FREE_AND_SET_NULL macro where appropriate
This commit is contained in:
GriffinR 2022-06-03 11:07:38 -04:00 committed by GitHub
commit 817fcb1c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 34 additions and 73 deletions

View File

@ -594,8 +594,7 @@ static void StatsChangeAnimation_Step3(u8 taskId)
if (gTasks[taskId].data[6] == 1)
gSprites[gTasks[taskId].data[7]].oam.priority++;
Free(sAnimStatsChangeData);
sAnimStatsChangeData = NULL;
FREE_AND_SET_NULL(sAnimStatsChangeData);
DestroyAnimVisualTask(taskId);
break;
}

View File

@ -1131,8 +1131,7 @@ static void CB2_InitSelectScreen(void)
switch (gMain.state)
{
case 0:
if (sFactorySelectMons != NULL)
FREE_AND_SET_NULL(sFactorySelectMons);
TRY_FREE_AND_SET_NULL(sFactorySelectMons);
SetHBlankCallback(NULL);
SetVBlankCallback(NULL);
CpuFill32(0, (void *)VRAM, VRAM_SIZE);

View File

@ -1498,8 +1498,7 @@ static void CB2_PreInitMultiBattle(void)
gBattleTypeFlags = *savedBattleTypeFlags;
gMain.savedCallback = *savedCallback;
SetMainCallback2(CB2_InitBattleInternal);
Free(sMultiPartnerPartyBuffer);
sMultiPartnerPartyBuffer = NULL;
FREE_AND_SET_NULL(sMultiPartnerPartyBuffer);
}
}
else if (gReceivedRemoteLinkPlayers == 0)
@ -1507,8 +1506,7 @@ static void CB2_PreInitMultiBattle(void)
gBattleTypeFlags = *savedBattleTypeFlags;
gMain.savedCallback = *savedCallback;
SetMainCallback2(CB2_InitBattleInternal);
Free(sMultiPartnerPartyBuffer);
sMultiPartnerPartyBuffer = NULL;
FREE_AND_SET_NULL(sMultiPartnerPartyBuffer);
}
break;
}
@ -1544,8 +1542,7 @@ static void CB2_PreInitIngamePlayerPartnerBattle(void)
gBattleTypeFlags = *savedBattleTypeFlags;
gMain.savedCallback = *savedCallback;
SetMainCallback2(CB2_InitBattleInternal);
Free(sMultiPartnerPartyBuffer);
sMultiPartnerPartyBuffer = NULL;
FREE_AND_SET_NULL(sMultiPartnerPartyBuffer);
}
break;
}

View File

@ -1672,8 +1672,7 @@ static bool8 InitEasyChatScreenStruct(u8 type, u16 *words, u8 displayedPersonTyp
static void FreeEasyChatScreenStruct(void)
{
if (sEasyChatScreen != NULL)
FREE_AND_SET_NULL(sEasyChatScreen);
TRY_FREE_AND_SET_NULL(sEasyChatScreen);
}
// Returns the function ID of the action to take as a result of player's input.
@ -3075,8 +3074,7 @@ static bool8 LoadEasyChatScreen(void)
static void FreeEasyChatScreenControl(void)
{
if (sScreenControl)
FREE_AND_SET_NULL(sScreenControl);
TRY_FREE_AND_SET_NULL(sScreenControl);
}
static void StartEasyChatFunction(u16 funcId)
@ -5573,8 +5571,7 @@ static bool8 InitEasyChatScreenWordData(void)
static void FreeEasyChatScreenWordData(void)
{
if (sWordData)
FREE_AND_SET_NULL(sWordData);
TRY_FREE_AND_SET_NULL(sWordData);
}
static void SetUnlockedEasyChatGroups(void)

View File

@ -816,8 +816,7 @@ static void Task_EvolutionScene(u8 taskId)
DestroyTask(taskId);
FreeMonSpritesGfx();
Free(sEvoStructPtr);
sEvoStructPtr = NULL;
FREE_AND_SET_NULL(sEvoStructPtr);
FreeAllWindowBuffers();
SetMainCallback2(gCB2_AfterEvolution);
}
@ -1223,8 +1222,7 @@ static void Task_TradeEvolutionScene(u8 taskId)
if (!IsTextPrinterActive(0))
{
DestroyTask(taskId);
Free(sEvoStructPtr);
sEvoStructPtr = NULL;
FREE_AND_SET_NULL(sEvoStructPtr);
gTextFlags.useAlternateDownArrow = 0;
SetMainCallback2(gCB2_AfterEvolution);
}

View File

@ -192,10 +192,7 @@ static void FieldUpdateRegionMap(void)
{
FreeRegionMapIconResources();
SetMainCallback2(sFieldRegionMapHandler->callback);
if (sFieldRegionMapHandler != NULL)
{
FREE_AND_SET_NULL(sFieldRegionMapHandler);
}
TRY_FREE_AND_SET_NULL(sFieldRegionMapHandler);
FreeAllWindowBuffers();
}
break;

View File

@ -529,10 +529,8 @@ static void Task_Hof_TrySaveData(u8 taskId)
UnsetBgTilemapBuffer(3);
FreeAllWindowBuffers();
if (sHofGfxPtr != NULL)
FREE_AND_SET_NULL(sHofGfxPtr);
if (sHofMonPtr != NULL)
FREE_AND_SET_NULL(sHofMonPtr);
TRY_FREE_AND_SET_NULL(sHofGfxPtr);
TRY_FREE_AND_SET_NULL(sHofMonPtr);
DestroyTask(taskId);
}
@ -773,10 +771,8 @@ static void Task_Hof_HandleExit(u8 taskId)
ResetBgsAndClearDma3BusyFlags(0);
DestroyTask(taskId);
if (sHofGfxPtr != NULL)
FREE_AND_SET_NULL(sHofGfxPtr);
if (sHofMonPtr != NULL)
FREE_AND_SET_NULL(sHofMonPtr);
TRY_FREE_AND_SET_NULL(sHofGfxPtr);
TRY_FREE_AND_SET_NULL(sHofMonPtr);
StartCredits();
}
@ -1081,10 +1077,8 @@ static void Task_HofPC_HandleExit(u8 taskId)
ResetBgsAndClearDma3BusyFlags(0);
DestroyTask(taskId);
if (sHofGfxPtr != NULL)
FREE_AND_SET_NULL(sHofGfxPtr);
if (sHofMonPtr != NULL)
FREE_AND_SET_NULL(sHofMonPtr);
TRY_FREE_AND_SET_NULL(sHofGfxPtr);
TRY_FREE_AND_SET_NULL(sHofMonPtr);
ReturnFromHallOfFamePC();
}

View File

@ -44,8 +44,7 @@ u32 MysteryGiftClient_Run(u16 * endVal)
{
*endVal = sClient->param;
MysteryGiftClient_Free(sClient);
Free(sClient);
sClient = NULL;
FREE_AND_SET_NULL(sClient);
}
return result;
}

View File

@ -44,8 +44,7 @@ u32 MysterGiftServer_Run(u16 * endVal)
{
*endVal = sServer->param;
MysteryGiftServer_Free(sServer);
Free(sServer);
sServer = NULL;
FREE_AND_SET_NULL(sServer);
}
return result;
}

View File

@ -207,8 +207,7 @@ void WonderCard_Destroy(void)
if (sWonderCardData != NULL)
{
*sWonderCardData = (struct WonderCardData){};
Free(sWonderCardData);
sWonderCardData = NULL;
FREE_AND_SET_NULL(sWonderCardData);
}
}
@ -660,8 +659,7 @@ void WonderNews_Destroy(void)
if (sWonderNewsData != NULL)
{
*sWonderNewsData = (struct WonderNewsData){};
Free(sWonderNewsData);
sWonderNewsData = NULL;
FREE_AND_SET_NULL(sWonderNewsData);
}
}

View File

@ -5417,8 +5417,7 @@ static bool32 WaitForWallpaperGfxLoad(void)
if (IsDma3ManagerBusyWithBgCopy())
return FALSE;
if (sStorage->wallpaperTiles != NULL)
FREE_AND_SET_NULL(sStorage->wallpaperTiles);
TRY_FREE_AND_SET_NULL(sStorage->wallpaperTiles);
return TRUE;
}

View File

@ -557,8 +557,7 @@ void *GetSubstructPtr(u32 index)
void FreePokenavSubstruct(u32 index)
{
if (gPokenavResources->substructPtrs[index] != NULL)
FREE_AND_SET_NULL(gPokenavResources->substructPtrs[index]);
TRY_FREE_AND_SET_NULL(gPokenavResources->substructPtrs[index]);
}
u32 GetPokenavMode(void)

View File

@ -2024,11 +2024,7 @@ static void CB_ExitFlyMap(void)
{
SetMainCallback2(CB2_ReturnToPartyMenuFromFlyMap);
}
if (sFlyMap != NULL)
{
free(sFlyMap);
sFlyMap = NULL;
}
TRY_FREE_AND_SET_NULL(sFlyMap);
FreeAllWindowBuffers();
}
break;

View File

@ -101,8 +101,7 @@ void FreeRotatingTilePuzzle(void)
{
u8 id;
if (sRotatingTilePuzzle != NULL)
FREE_AND_SET_NULL(sRotatingTilePuzzle);
TRY_FREE_AND_SET_NULL(sRotatingTilePuzzle);
id = GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0);
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[id]);

View File

@ -1756,14 +1756,10 @@ static bool8 SlotTask_FreeDataStructures(struct Task *task)
FREE_AND_SET_NULL(sImageTable_DigitalDisplay_Number);
FREE_AND_SET_NULL(sImageTable_DigitalDisplay_Pokeball);
FREE_AND_SET_NULL(sImageTable_DigitalDisplay_DPad);
if (sImageTable_ReelTimePikachu != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
if (sImageTable_ReelTimeMachineAntennae != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
if (sImageTable_ReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
if (sImageTable_BrokenReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
FREE_AND_SET_NULL(sMenuGfx);
FREE_AND_SET_NULL(sSelectedPikaPowerTile);
FREE_AND_SET_NULL(sReelOverlay_Tilemap);
@ -4178,8 +4174,7 @@ static void CreateReelTimePikachuSprite(void)
static void DestroyReelTimePikachuSprite(void)
{
DestroySprite(&gSprites[sSlotMachine->reelTimePikachuSpriteId]);
if (sImageTable_ReelTimePikachu != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimePikachu);
}
static void SpriteCB_ReelTimePikachu(struct Sprite *sprite)
@ -4308,10 +4303,8 @@ static void DestroyReelTimeMachineSprites(void)
for (i = 0; i < ARRAY_COUNT(sSlotMachine->reelTimeMachineSpriteIds); i++)
DestroySprite(&gSprites[sSlotMachine->reelTimeMachineSpriteIds[i]]);
if (sImageTable_ReelTimeMachineAntennae != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
if (sImageTable_ReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachineAntennae);
TRY_FREE_AND_SET_NULL(sImageTable_ReelTimeMachine);
for (i = 0; i < ARRAY_COUNT(sSlotMachine->reelTimeNumberSpriteIds); i++)
DestroySprite(&gSprites[sSlotMachine->reelTimeNumberSpriteIds[i]]);
@ -4328,8 +4321,7 @@ static void DestroyReelTimeShadowSprites(void)
static void DestroyBrokenReelTimeMachineSprite(void)
{
DestroySprite(&gSprites[sSlotMachine->reelTimeBrokenMachineSpriteId]);
if (sImageTable_BrokenReelTimeMachine != NULL)
FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
TRY_FREE_AND_SET_NULL(sImageTable_BrokenReelTimeMachine);
}
#define sDelayTimer data[0]

View File

@ -2160,8 +2160,7 @@ static bool32 IsDisplaySubtask0Active(void)
static void FreeDisplay(void)
{
FreeSprites();
if (sDisplay)
FREE_AND_SET_NULL(sDisplay);
TRY_FREE_AND_SET_NULL(sDisplay);
FreeAllWindowBuffers();
gScanlineEffect.state = 3;