mirror of
https://github.com/opentx/opentx.git
synced 2025-07-23 00:05:17 +03:00
Fixed many memory leaks
This commit is contained in:
parent
b7cc3a5ef2
commit
df954ae483
13 changed files with 76 additions and 10 deletions
|
@ -123,5 +123,7 @@ int main(int argc, char *argv[])
|
||||||
delete splash;
|
delete splash;
|
||||||
delete mainWin;
|
delete mainWin;
|
||||||
|
|
||||||
|
UnregisterFirmwares();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "firmwares/th9x/th9xinterface.h"
|
#include "firmwares/th9x/th9xinterface.h"
|
||||||
#include "firmwares/gruvin9x/gruvin9xinterface.h"
|
#include "firmwares/gruvin9x/gruvin9xinterface.h"
|
||||||
#include "firmwares/opentx/opentxinterface.h"
|
#include "firmwares/opentx/opentxinterface.h"
|
||||||
|
#include "firmwares/opentx/opentxeeprom.h"
|
||||||
#include "firmwares/ersky9x/ersky9xinterface.h"
|
#include "firmwares/ersky9x/ersky9xinterface.h"
|
||||||
#include "appdata.h"
|
#include "appdata.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
@ -1202,6 +1203,15 @@ void RegisterEepromInterfaces()
|
||||||
eepromInterfaces.push_back(new Er9xInterface());
|
eepromInterfaces.push_back(new Er9xInterface());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnregisterEepromInterfaces()
|
||||||
|
{
|
||||||
|
foreach(EEPROMInterface * intf, eepromInterfaces) {
|
||||||
|
//std::cout << "UnregisterEepromInterfaces(): deleting " << std::hex << reinterpret_cast<uint64_t>(intf) << std::dec << std::endl;
|
||||||
|
delete intf;
|
||||||
|
}
|
||||||
|
OpenTxEepromCleanup();
|
||||||
|
}
|
||||||
|
|
||||||
QList<FirmwareInfo *> firmwares;
|
QList<FirmwareInfo *> firmwares;
|
||||||
FirmwareVariant default_firmware_variant;
|
FirmwareVariant default_firmware_variant;
|
||||||
FirmwareVariant current_firmware_variant;
|
FirmwareVariant current_firmware_variant;
|
||||||
|
@ -1214,6 +1224,12 @@ void RegisterFirmwares()
|
||||||
RegisterEepromInterfaces();
|
RegisterEepromInterfaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnregisterFirmwares() {
|
||||||
|
UnregisterEepromInterfaces();
|
||||||
|
UnregisterOpen9xFirmwares();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size)
|
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size)
|
||||||
{
|
{
|
||||||
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
|
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
|
||||||
|
|
|
@ -1245,6 +1245,7 @@ inline void applyStickModeToModel(ModelData &model, unsigned int mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterFirmwares();
|
void RegisterFirmwares();
|
||||||
|
void UnregisterFirmwares();
|
||||||
|
|
||||||
bool LoadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index);
|
bool LoadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index);
|
||||||
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, int size);
|
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, int size);
|
||||||
|
@ -1269,6 +1270,8 @@ class FirmwareInfo {
|
||||||
|
|
||||||
virtual ~FirmwareInfo()
|
virtual ~FirmwareInfo()
|
||||||
{
|
{
|
||||||
|
//std::cout << "~FirmwareInfo(): id: " << id.toUtf8().constData() << " name: " << name.toUtf8().constData() << std::endl;
|
||||||
|
if (eepromInterface) delete eepromInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
FirmwareInfo(const QString & id, const QString & name, EEPROMInterface * eepromInterface, const QString & url = QString(), const QString & stamp = QString(), const QString & rnurl = QString(), bool voice = false):
|
FirmwareInfo(const QString & id, const QString & name, EEPROMInterface * eepromInterface, const QString & url = QString(), const QString & stamp = QString(), const QString & rnurl = QString(), bool voice = false):
|
||||||
|
|
|
@ -129,12 +129,12 @@ class SwitchesConversionTable: public ConversionTable {
|
||||||
SwitchesConversionTable * table;
|
SwitchesConversionTable * table;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static std::list<Cache> internalCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static SwitchesConversionTable * getInstance(BoardEnum board, unsigned int version, unsigned long flags=0)
|
static SwitchesConversionTable * getInstance(BoardEnum board, unsigned int version, unsigned long flags=0)
|
||||||
{
|
{
|
||||||
static std::list<Cache> internalCache;
|
|
||||||
|
|
||||||
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) {
|
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) {
|
||||||
Cache element = *it;
|
Cache element = *it;
|
||||||
if (element.board == board && element.version == version && element.flags == flags)
|
if (element.board == board && element.version == version && element.flags == flags)
|
||||||
|
@ -145,8 +145,17 @@ class SwitchesConversionTable: public ConversionTable {
|
||||||
internalCache.push_back(element);
|
internalCache.push_back(element);
|
||||||
return element.table;
|
return element.table;
|
||||||
}
|
}
|
||||||
|
static void Cleanup() {
|
||||||
|
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) {
|
||||||
|
Cache element = *it;
|
||||||
|
std::cout << "~SwitchesConversionTable(): deleting " << std::hex << reinterpret_cast<uint64_t>(element.table) << std::dec << std::endl;
|
||||||
|
if (element.table) delete element.table;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::list<SwitchesConversionTable::Cache> SwitchesConversionTable::internalCache;
|
||||||
|
|
||||||
#define FLAG_NONONE 0x01
|
#define FLAG_NONONE 0x01
|
||||||
#define FLAG_NOSWITCHES 0x02
|
#define FLAG_NOSWITCHES 0x02
|
||||||
#define FLAG_NOTELEMETRY 0x04
|
#define FLAG_NOTELEMETRY 0x04
|
||||||
|
@ -281,13 +290,12 @@ class SourcesConversionTable: public ConversionTable {
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
SourcesConversionTable * table;
|
SourcesConversionTable * table;
|
||||||
};
|
};
|
||||||
|
static std::list<Cache> internalCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static SourcesConversionTable * getInstance(BoardEnum board, unsigned int version, unsigned int variant, unsigned long flags=0)
|
static SourcesConversionTable * getInstance(BoardEnum board, unsigned int version, unsigned int variant, unsigned long flags=0)
|
||||||
{
|
{
|
||||||
static std::list<Cache> internalCache;
|
|
||||||
|
|
||||||
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) {
|
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) {
|
||||||
Cache element = *it;
|
Cache element = *it;
|
||||||
if (element.board == board && element.version == version && element.variant == variant && element.flags == flags)
|
if (element.board == board && element.version == version && element.variant == variant && element.flags == flags)
|
||||||
|
@ -298,8 +306,22 @@ class SourcesConversionTable: public ConversionTable {
|
||||||
internalCache.push_back(element);
|
internalCache.push_back(element);
|
||||||
return element.table;
|
return element.table;
|
||||||
}
|
}
|
||||||
|
static void Cleanup() {
|
||||||
|
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) {
|
||||||
|
Cache element = *it;
|
||||||
|
//std::cout << "~SourcesConversionTable(): deleting " << std::hex << reinterpret_cast<uint64_t>(element.table) << std::dec << std::endl;
|
||||||
|
if (element.table) delete element.table;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::list<SourcesConversionTable::Cache> SourcesConversionTable::internalCache;
|
||||||
|
|
||||||
|
void OpenTxEepromCleanup(void){
|
||||||
|
SourcesConversionTable::Cleanup();
|
||||||
|
SwitchesConversionTable::Cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
ThrottleSourceConversionTable::ThrottleSourceConversionTable(BoardEnum board, unsigned int version)
|
ThrottleSourceConversionTable::ThrottleSourceConversionTable(BoardEnum board, unsigned int version)
|
||||||
{
|
{
|
||||||
int val=0;
|
int val=0;
|
||||||
|
@ -1436,6 +1458,9 @@ class LogicalSwitchField: public TransformedField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~LogicalSwitchField() {
|
||||||
|
if (andswitchesConversionTable) delete andswitchesConversionTable;
|
||||||
|
}
|
||||||
virtual void beforeExport()
|
virtual void beforeExport()
|
||||||
{
|
{
|
||||||
if (csw.func == LS_FN_TIMER) {
|
if (csw.func == LS_FN_TIMER) {
|
||||||
|
|
|
@ -144,4 +144,5 @@ class OpenTxModelData: public TransformedField {
|
||||||
ChannelsConversionTable channelsConversionTable;
|
ChannelsConversionTable channelsConversionTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void OpenTxEepromCleanup(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1232,3 +1232,10 @@ void RegisterOpen9xFirmwares()
|
||||||
firmwares.push_back(open9x);
|
firmwares.push_back(open9x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnregisterOpen9xFirmwares() {
|
||||||
|
foreach (FirmwareInfo * f, firmwares) {
|
||||||
|
//std::cout << "UnregisterOpen9xFirmwares(): deleting " << std::hex << reinterpret_cast<uint64_t>(f) << std::dec << std::endl;
|
||||||
|
delete f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -164,5 +164,6 @@ class Open9xFirmware: public FirmwareInfo {
|
||||||
};
|
};
|
||||||
|
|
||||||
void RegisterOpen9xFirmwares();
|
void RegisterOpen9xFirmwares();
|
||||||
|
void UnregisterOpen9xFirmwares();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "appdata.h"
|
#include "appdata.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "simulatordialog.h"
|
#include "simulatordialog.h"
|
||||||
|
#include "simulatorinterface.h"
|
||||||
#include "flashinterface.h"
|
#include "flashinterface.h"
|
||||||
|
|
||||||
const QColor colors[C9X_MAX_CURVES] = {
|
const QColor colors[C9X_MAX_CURVES] = {
|
||||||
|
@ -905,7 +906,9 @@ CompanionIcon::CompanionIcon(QString baseimage)
|
||||||
|
|
||||||
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
||||||
{
|
{
|
||||||
if (GetEepromInterface()->getSimulator()) {
|
SimulatorInterface * si = GetEepromInterface()->getSimulator();
|
||||||
|
if (si) {
|
||||||
|
delete si;
|
||||||
RadioData * simuData = new RadioData(radioData);
|
RadioData * simuData = new RadioData(radioData);
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
if (modelIdx >= 0) {
|
if (modelIdx >= 0) {
|
||||||
|
|
|
@ -1681,10 +1681,10 @@ void MainWindow::createActions()
|
||||||
void MainWindow::createMenus()
|
void MainWindow::createMenus()
|
||||||
|
|
||||||
{
|
{
|
||||||
QMenu *recentFileMenu=new QMenu(tr("Recent Models+Settings"));
|
QMenu *recentFileMenu=new QMenu(tr("Recent Models+Settings"), this);
|
||||||
QMenu *languageMenu=new QMenu(tr("Set Menu Language"));
|
QMenu *languageMenu=new QMenu(tr("Set Menu Language"), this);
|
||||||
QMenu *themeMenu=new QMenu(tr("Set Icon Theme"));
|
QMenu *themeMenu=new QMenu(tr("Set Icon Theme"), this);
|
||||||
QMenu *iconThemeSizeMenu=new QMenu(tr("Set Icon Size"));
|
QMenu *iconThemeSizeMenu=new QMenu(tr("Set Icon Size"), this);
|
||||||
|
|
||||||
fileMenu = menuBar()->addMenu(tr("File"));
|
fileMenu = menuBar()->addMenu(tr("File"));
|
||||||
fileMenu->addAction(newAct);
|
fileMenu->addAction(newAct);
|
||||||
|
@ -1783,7 +1783,7 @@ QMenu *MainWindow::createRecentFileMenu()
|
||||||
|
|
||||||
QMenu *MainWindow::createProfilesMenu()
|
QMenu *MainWindow::createProfilesMenu()
|
||||||
{
|
{
|
||||||
QMenu *profilesMenu=new QMenu(tr("Radio Profile"));
|
QMenu *profilesMenu=new QMenu(tr("Radio Profile"), this);
|
||||||
int i;
|
int i;
|
||||||
for ( i = 0; i < MAX_PROFILES; ++i) {
|
for ( i = 0; i < MAX_PROFILES; ++i) {
|
||||||
profilesMenu->addAction(profileActs[i]);
|
profilesMenu->addAction(profileActs[i]);
|
||||||
|
|
|
@ -82,6 +82,10 @@ MdiChild::MdiChild():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MdiChild::~MdiChild() {
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
void MdiChild::qSleep(int ms)
|
void MdiChild::qSleep(int ms)
|
||||||
{
|
{
|
||||||
if (ms<0)
|
if (ms<0)
|
||||||
|
|
|
@ -61,6 +61,7 @@ class MdiChild : public QWidget
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MdiChild();
|
MdiChild();
|
||||||
|
~MdiChild();
|
||||||
|
|
||||||
void newFile();
|
void newFile();
|
||||||
bool loadFile(const QString &fileName, bool resetCurrentFile=true);
|
bool loadFile(const QString &fileName, bool resetCurrentFile=true);
|
||||||
|
|
|
@ -142,6 +142,7 @@ SimulatorDialogTaranis::~SimulatorDialogTaranis()
|
||||||
SimulatorDialog::~SimulatorDialog()
|
SimulatorDialog::~SimulatorDialog()
|
||||||
{
|
{
|
||||||
delete timer;
|
delete timer;
|
||||||
|
if (simulator) delete simulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorDialog::closeEvent (QCloseEvent *)
|
void SimulatorDialog::closeEvent (QCloseEvent *)
|
||||||
|
|
|
@ -48,6 +48,8 @@ class SimulatorInterface {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual ~SimulatorInterface() {};
|
||||||
|
|
||||||
virtual void start(QByteArray & eeprom, bool tests=true) = 0;
|
virtual void start(QByteArray & eeprom, bool tests=true) = 0;
|
||||||
|
|
||||||
virtual void start(const char * filename, bool tests=true) = 0;
|
virtual void start(const char * filename, bool tests=true) = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue