Skip to content

Commit

Permalink
Firmware: Ensure that memory leaks don't happen when errors occur.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerman committed Mar 10, 2019
1 parent 4281747 commit 8fa60fa
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions desmume/src/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ bool CFIRMWARE::load(const char *firmwareFilePath)
this->_isLoaded = NDS_ReadFirmwareDataFromFile(firmwareFilePath, newFirmwareData, &fileSize, NULL, NULL);
if (!this->_isLoaded)
{
delete newFirmwareData;
return this->_isLoaded;
}

Expand Down Expand Up @@ -333,13 +334,15 @@ bool CFIRMWARE::unpack()
arm9Size = this->_decrypt(&workingFirmwareData->_raw[part1addr], tmp_data9);
if (tmp_data9 == NULL)
{
delete workingFirmwareData;
return false;
}

arm7Size = this->_decrypt(&workingFirmwareData->_raw[part2addr], tmp_data7);
if (tmp_data7 == NULL)
{
delete [] tmp_data9;
delete workingFirmwareData;
return false;
}

Expand All @@ -350,6 +353,7 @@ bool CFIRMWARE::unpack()
INFO("Firmware: ERROR: the boot code CRC16 (0x%04X) doesn't match the value in the firmware header (0x%04X)", crc16_mine, this->_header.part12_boot_crc16);
delete [] tmp_data9;
delete [] tmp_data7;
delete workingFirmwareData;
return false;
}

Expand Down Expand Up @@ -419,13 +423,15 @@ bool CFIRMWARE::unpack()
arm9Size = this->_decompress(&workingFirmwareData->_raw[part1addr], tmp_data9);
if (tmp_data9 == NULL)
{
delete workingFirmwareData;
return false;
}

arm7Size = this->_decompress(&workingFirmwareData->_raw[part2addr], tmp_data7);
if (tmp_data7 == NULL)
{
delete [] tmp_data9;
delete workingFirmwareData;
return false;
};
// Copy firmware boot codes to their respective locations
Expand Down

0 comments on commit 8fa60fa

Please sign in to comment.