mirror of
https://github.com/opentx/opentx.git
synced 2025-07-23 16:25:16 +03:00
cppcheck experiment. A couple of memory leaks fixed
This commit is contained in:
parent
33091c295f
commit
86c0678273
13 changed files with 35 additions and 41 deletions
|
@ -1050,7 +1050,7 @@ void RegisterFirmwares()
|
|||
RegisterEepromInterfaces();
|
||||
}
|
||||
|
||||
bool LoadEeprom(RadioData &radioData, uint8_t *eeprom, int size)
|
||||
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size)
|
||||
{
|
||||
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
|
||||
if (eepromInterface->load(radioData, eeprom, size))
|
||||
|
|
|
@ -1082,7 +1082,7 @@ class EEPROMInterface
|
|||
|
||||
inline BoardEnum getBoard() { return board; }
|
||||
|
||||
virtual bool load(RadioData &radioData, uint8_t *eeprom, int size) = 0;
|
||||
virtual bool load(RadioData &radioData, const uint8_t *eeprom, int size) = 0;
|
||||
|
||||
virtual bool loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) = 0;
|
||||
|
||||
|
@ -1211,7 +1211,7 @@ inline void applyStickModeToModel(ModelData &model, unsigned int mode)
|
|||
void RegisterFirmwares();
|
||||
|
||||
bool LoadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index);
|
||||
bool LoadEeprom(RadioData &radioData, uint8_t *eeprom, int size);
|
||||
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, int size);
|
||||
bool LoadEepromXml(RadioData &radioData, QDomDocument &doc);
|
||||
|
||||
struct Option {
|
||||
|
|
|
@ -114,7 +114,7 @@ bool Er9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Er9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
||||
bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
|
||||
{
|
||||
std::cout << "trying er9x import... ";
|
||||
|
||||
|
@ -123,7 +123,7 @@ bool Er9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!efile->EeFsOpen(eeprom, size, BOARD_STOCK)) {
|
||||
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) {
|
||||
std::cout << "wrong file system\n";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class Er9xInterface : public EEPROMInterface
|
|||
|
||||
virtual const int getMaxModels();
|
||||
|
||||
virtual bool load(RadioData &, uint8_t * eeprom, int size);
|
||||
virtual bool load(RadioData &, const uint8_t * eeprom, int size);
|
||||
|
||||
virtual bool loadBackup(RadioData &, uint8_t * eeprom, int esize, int index);
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ bool Ersky9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Ersky9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
||||
bool Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
|
||||
{
|
||||
std::cout << "trying ersky9x import... ";
|
||||
|
||||
|
@ -160,7 +160,7 @@ bool Ersky9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!efile->EeFsOpen(eeprom, size, BOARD_SKY9X)) {
|
||||
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_SKY9X)) {
|
||||
std::cout << "wrong file system\n";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class Ersky9xInterface : public EEPROMInterface
|
|||
|
||||
virtual const int getMaxModels();
|
||||
|
||||
virtual bool load(RadioData &, uint8_t * eeprom, int size);
|
||||
virtual bool load(RadioData &, const uint8_t * eeprom, int size);
|
||||
|
||||
virtual bool loadBackup(RadioData &, uint8_t * eeprom, int esize, int index);
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ bool Gruvin9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
|
|||
}
|
||||
|
||||
|
||||
bool Gruvin9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
||||
bool Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
|
||||
{
|
||||
std::cout << "trying " << getName() << " import... ";
|
||||
|
||||
|
@ -108,7 +108,7 @@ bool Gruvin9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!efile->EeFsOpen(eeprom, size, BOARD_STOCK)) {
|
||||
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) {
|
||||
std::cout << "wrong file system\n";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class Gruvin9xInterface : public EEPROMInterface
|
|||
|
||||
virtual const int getMaxModels();
|
||||
|
||||
virtual bool load(RadioData &, uint8_t *eeprom, int size);
|
||||
virtual bool load(RadioData &, const uint8_t *eeprom, int size);
|
||||
|
||||
virtual bool loadBackup(RadioData &, uint8_t *eeprom,int esize, int index);
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ bool OpenTxInterface::loadxml(RadioData &radioData, QDomDocument &doc)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool OpenTxInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
||||
bool OpenTxInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
|
||||
{
|
||||
std::cout << "trying " << getName() << " import...";
|
||||
|
||||
|
@ -305,7 +305,8 @@ bool OpenTxInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
|||
if (notnull) {
|
||||
std::cout << " wrong size (" << size << ")\n";
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(NULL, "companion", QObject::tr("Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used"));
|
||||
size=2048;
|
||||
}
|
||||
|
@ -315,7 +316,7 @@ bool OpenTxInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
|||
}
|
||||
}
|
||||
|
||||
if (!efile->EeFsOpen(eeprom, size, board)) {
|
||||
if (!efile->EeFsOpen((uint8_t *)eeprom, size, board)) {
|
||||
std::cout << " wrong file system\n";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class OpenTxInterface : public EEPROMInterface
|
|||
|
||||
virtual const int getMaxModels();
|
||||
|
||||
virtual bool load(RadioData &, uint8_t *eeprom, int size);
|
||||
virtual bool load(RadioData &, const uint8_t *eeprom, int size);
|
||||
|
||||
virtual bool loadBackup(RadioData &, uint8_t *eeprom, int esize, int index);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ bool Th9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Th9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
||||
bool Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
|
||||
{
|
||||
std::cout << "trying th9x import... ";
|
||||
|
||||
|
@ -71,7 +71,7 @@ bool Th9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!efile->EeFsOpen(eeprom, size, BOARD_STOCK)) {
|
||||
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) {
|
||||
std::cout << "wrong file system\n";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class Th9xInterface : public EEPROMInterface
|
|||
|
||||
virtual const int getMaxModels();
|
||||
|
||||
virtual bool load(RadioData &, uint8_t *eeprom, int size);
|
||||
virtual bool load(RadioData &, const uint8_t *eeprom, int size);
|
||||
|
||||
virtual bool loadBackup(RadioData &, uint8_t *eeprom, int esize, int index);
|
||||
|
||||
|
|
|
@ -468,7 +468,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
|
|||
if (OldFwRev == 0) {
|
||||
showcheckForUpdatesResult = false; // update is available - do not show dialog
|
||||
QString rn = GetFirmware(fwToUpdate)->rnurl;
|
||||
QAbstractButton *rnButton;
|
||||
QAbstractButton *rnButton = NULL;
|
||||
msgBox.setWindowTitle("Companion");
|
||||
msgBox.setInformativeText(tr("Firmware %1 does not seem to have ever been downloaded.\nVersion %2 is available.\nDo you want to download it now ?").arg(fwToUpdate).arg(NewFwRev));
|
||||
QAbstractButton *YesButton = msgBox.addButton(trUtf8("Yes"), QMessageBox::YesRole);
|
||||
|
@ -1198,17 +1198,15 @@ bool MainWindow::isValidEEPROM(QString eepromfile)
|
|||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return false;
|
||||
eeprom_size = file.size();
|
||||
uint8_t *eeprom = (uint8_t *)malloc(eeprom_size);
|
||||
QByteArray eeprom(eeprom_size, 0);
|
||||
QTextStream inputStream(&file);
|
||||
eeprom_size = HexInterface(inputStream).load(eeprom, eeprom_size);
|
||||
eeprom_size = HexInterface(inputStream).load((uint8_t *)eeprom.data(), eeprom_size);
|
||||
if (!eeprom_size) {
|
||||
free(eeprom);
|
||||
return false;
|
||||
}
|
||||
file.close();
|
||||
RadioData * radioData = new RadioData();
|
||||
bool result = LoadEeprom(*radioData, eeprom, eeprom_size);
|
||||
free(eeprom);
|
||||
bool result = LoadEeprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size);
|
||||
delete radioData;
|
||||
return result;
|
||||
}
|
||||
|
@ -1216,17 +1214,14 @@ bool MainWindow::isValidEEPROM(QString eepromfile)
|
|||
if (!file.open(QFile::ReadOnly))
|
||||
return false;
|
||||
eeprom_size = file.size();
|
||||
uint8_t *eeprom = (uint8_t *)malloc(eeprom_size);
|
||||
memset(eeprom, 0, eeprom_size);
|
||||
long read = file.read((char*)eeprom, eeprom_size);
|
||||
QByteArray eeprom(eeprom_size, 0);
|
||||
long read = file.read(eeprom.data(), eeprom_size);
|
||||
file.close();
|
||||
if (read != eeprom_size) {
|
||||
free(eeprom);
|
||||
return false;
|
||||
}
|
||||
RadioData * radioData = new RadioData();
|
||||
bool result = LoadEeprom(*radioData, eeprom, eeprom_size);
|
||||
free(eeprom);
|
||||
bool result = LoadEeprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size);
|
||||
delete radioData;
|
||||
return result;
|
||||
}
|
||||
|
@ -1280,24 +1275,23 @@ bool MainWindow::convertEEPROM(QString backupFile, QString restoreFile, QString
|
|||
if (!file.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
|
||||
uint8_t *eeprom = (uint8_t *)malloc(eeprom_size);
|
||||
long result = file.read((char*)eeprom, eeprom_size);
|
||||
QByteArray eeprom(eeprom_size, 0);
|
||||
long result = file.read(eeprom.data(), eeprom_size);
|
||||
file.close();
|
||||
|
||||
QSharedPointer<RadioData> radioData = QSharedPointer<RadioData>(new RadioData());
|
||||
if (!LoadEeprom(*radioData, eeprom, eeprom_size) || !firmware->saveEEPROM(eeprom, *radioData, variant, version))
|
||||
if (!LoadEeprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size) || !firmware->saveEEPROM((uint8_t *)eeprom.data(), *radioData, variant, version))
|
||||
return false;
|
||||
|
||||
QFile file2(restoreFile);
|
||||
if (!file2.open(QIODevice::WriteOnly))
|
||||
return false;
|
||||
|
||||
result = file2.write((char*)eeprom, eeprom_size);
|
||||
result = file2.write(eeprom.constData(), eeprom_size);
|
||||
file2.close();
|
||||
if (result != eeprom_size)
|
||||
return false;
|
||||
|
||||
free(eeprom);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2060,15 +2054,14 @@ int MainWindow::getEpromVersion(QString fileName)
|
|||
QMessageBox::critical(this, tr("Error"),tr("Error opening file %1:\n%2.").arg(fileName).arg(file.errorString()));
|
||||
return -1;
|
||||
}
|
||||
uint8_t *eeprom = (uint8_t *)malloc(eeprom_size);
|
||||
memset(eeprom, 0, eeprom_size);
|
||||
long result = file.read((char*)eeprom, eeprom_size);
|
||||
QByteArray eeprom(eeprom_size, 0);
|
||||
long result = file.read(eeprom.data(), eeprom_size);
|
||||
file.close();
|
||||
if (result != eeprom_size) {
|
||||
QMessageBox::critical(this, tr("Error"),tr("Error reading file %1:\n%2.").arg(fileName).arg(file.errorString()));
|
||||
return -1;
|
||||
}
|
||||
if (!LoadEeprom(testData, eeprom, eeprom_size)) {
|
||||
if (!LoadEeprom(testData, (uint8_t *)eeprom.data(), eeprom_size)) {
|
||||
QMessageBox::critical(this, tr("Error"),tr("Invalid binary Models and Settings File %1").arg(fileName));
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue