Skip to content

Commit

Permalink
Avoid double-frees
Browse files Browse the repository at this point in the history
  • Loading branch information
AEFeinstein committed Jan 1, 2025
1 parent 6eb63f3 commit 5a39db6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
12 changes: 8 additions & 4 deletions main/asset_loaders/fs_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ bool loadFont(const char* name, font_t* font, bool spiRam)
*/
void freeFont(font_t* font)
{
// using uint8_t instead of char because a char will overflow to -128 after the last char is freed (\x7f)
for (uint8_t idx = 0; idx <= '~' - ' ' + 1; idx++)
if (font->height)
{
if (font->chars[idx].bitmap != NULL)
// using uint8_t instead of char because a char will overflow to -128 after the last char is freed (\x7f)
for (uint8_t idx = 0; idx <= '~' - ' ' + 1; idx++)
{
heap_caps_free(font->chars[idx].bitmap);
if (font->chars[idx].bitmap != NULL)
{
heap_caps_free(font->chars[idx].bitmap);
}
}
font->height = 0;
}
}
7 changes: 6 additions & 1 deletion main/asset_loaders/fs_wsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,10 @@ bool saveWsgNvs(const char* namespace, const char* key, const wsg_t* wsg)
*/
void freeWsg(wsg_t* wsg)
{
heap_caps_free(wsg->px);
if (wsg->w && wsg->h)
{
heap_caps_free(wsg->px);
wsg->h = 0;
wsg->w = 0;
}
}
1 change: 1 addition & 0 deletions main/modes/games/bigbug/gameData_bigbug.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void bb_freeGameData(bb_gameData_t* gameData)
if(gameData->loadoutScreenData!=NULL)
{
heap_caps_free(gameData->loadoutScreenData);
gameData->loadoutScreenData = NULL;
}
}

Expand Down
1 change: 1 addition & 0 deletions main/modes/games/bigbug/mode_bigbug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ static void bb_GameLoop_Loadout_Select(int64_t elapsedUs)
if(bigbug->gameData.loadoutScreenData->primingEffect >= 185)
{
heap_caps_free(bigbug->gameData.loadoutScreenData);
bigbug->gameData.loadoutScreenData = NULL;
bigbugMode.fnBackgroundDrawCallback = bb_BackgroundDrawCallback;
bigbug->gameData.screen = BIGBUG_GAME;
return;
Expand Down

0 comments on commit 5a39db6

Please sign in to comment.