mirror of
https://github.com/opentx/opentx.git
synced 2025-07-22 15:55:26 +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 mainWin;
|
||||
|
||||
UnregisterFirmwares();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "firmwares/th9x/th9xinterface.h"
|
||||
#include "firmwares/gruvin9x/gruvin9xinterface.h"
|
||||
#include "firmwares/opentx/opentxinterface.h"
|
||||
#include "firmwares/opentx/opentxeeprom.h"
|
||||
#include "firmwares/ersky9x/ersky9xinterface.h"
|
||||
#include "appdata.h"
|
||||
#include "helpers.h"
|
||||
|
@ -1202,6 +1203,15 @@ void RegisterEepromInterfaces()
|
|||
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;
|
||||
FirmwareVariant default_firmware_variant;
|
||||
FirmwareVariant current_firmware_variant;
|
||||
|
@ -1214,6 +1224,12 @@ void RegisterFirmwares()
|
|||
RegisterEepromInterfaces();
|
||||
}
|
||||
|
||||
void UnregisterFirmwares() {
|
||||
UnregisterEepromInterfaces();
|
||||
UnregisterOpen9xFirmwares();
|
||||
}
|
||||
|
||||
|
||||
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size)
|
||||
{
|
||||
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
|
||||
|
|
|
@ -1245,6 +1245,7 @@ inline void applyStickModeToModel(ModelData &model, unsigned int mode)
|
|||
}
|
||||
|
||||
void RegisterFirmwares();
|
||||
void UnregisterFirmwares();
|
||||
|
||||
bool LoadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index);
|
||||
bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, int size);
|
||||
|
@ -1269,6 +1270,8 @@ class 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):
|
||||
|
|
|
@ -129,12 +129,12 @@ class SwitchesConversionTable: public ConversionTable {
|
|||
SwitchesConversionTable * table;
|
||||
};
|
||||
|
||||
static std::list<Cache> internalCache;
|
||||
|
||||
public:
|
||||
|
||||
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++) {
|
||||
Cache element = *it;
|
||||
if (element.board == board && element.version == version && element.flags == flags)
|
||||
|
@ -145,8 +145,17 @@ class SwitchesConversionTable: public ConversionTable {
|
|||
internalCache.push_back(element);
|
||||
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_NOSWITCHES 0x02
|
||||
#define FLAG_NOTELEMETRY 0x04
|
||||
|
@ -281,13 +290,12 @@ class SourcesConversionTable: public ConversionTable {
|
|||
unsigned long flags;
|
||||
SourcesConversionTable * table;
|
||||
};
|
||||
static std::list<Cache> internalCache;
|
||||
|
||||
public:
|
||||
|
||||
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++) {
|
||||
Cache element = *it;
|
||||
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);
|
||||
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)
|
||||
{
|
||||
int val=0;
|
||||
|
@ -1436,6 +1458,9 @@ class LogicalSwitchField: public TransformedField {
|
|||
}
|
||||
}
|
||||
|
||||
~LogicalSwitchField() {
|
||||
if (andswitchesConversionTable) delete andswitchesConversionTable;
|
||||
}
|
||||
virtual void beforeExport()
|
||||
{
|
||||
if (csw.func == LS_FN_TIMER) {
|
||||
|
|
|
@ -144,4 +144,5 @@ class OpenTxModelData: public TransformedField {
|
|||
ChannelsConversionTable channelsConversionTable;
|
||||
};
|
||||
|
||||
void OpenTxEepromCleanup(void);
|
||||
#endif
|
||||
|
|
|
@ -1232,3 +1232,10 @@ void RegisterOpen9xFirmwares()
|
|||
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 UnregisterOpen9xFirmwares();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "appdata.h"
|
||||
#include "helpers.h"
|
||||
#include "simulatordialog.h"
|
||||
#include "simulatorinterface.h"
|
||||
#include "flashinterface.h"
|
||||
|
||||
const QColor colors[C9X_MAX_CURVES] = {
|
||||
|
@ -905,7 +906,9 @@ CompanionIcon::CompanionIcon(QString baseimage)
|
|||
|
||||
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
||||
{
|
||||
if (GetEepromInterface()->getSimulator()) {
|
||||
SimulatorInterface * si = GetEepromInterface()->getSimulator();
|
||||
if (si) {
|
||||
delete si;
|
||||
RadioData * simuData = new RadioData(radioData);
|
||||
unsigned int flags = 0;
|
||||
if (modelIdx >= 0) {
|
||||
|
|
|
@ -1681,10 +1681,10 @@ void MainWindow::createActions()
|
|||
void MainWindow::createMenus()
|
||||
|
||||
{
|
||||
QMenu *recentFileMenu=new QMenu(tr("Recent Models+Settings"));
|
||||
QMenu *languageMenu=new QMenu(tr("Set Menu Language"));
|
||||
QMenu *themeMenu=new QMenu(tr("Set Icon Theme"));
|
||||
QMenu *iconThemeSizeMenu=new QMenu(tr("Set Icon Size"));
|
||||
QMenu *recentFileMenu=new QMenu(tr("Recent Models+Settings"), this);
|
||||
QMenu *languageMenu=new QMenu(tr("Set Menu Language"), this);
|
||||
QMenu *themeMenu=new QMenu(tr("Set Icon Theme"), this);
|
||||
QMenu *iconThemeSizeMenu=new QMenu(tr("Set Icon Size"), this);
|
||||
|
||||
fileMenu = menuBar()->addMenu(tr("File"));
|
||||
fileMenu->addAction(newAct);
|
||||
|
@ -1783,7 +1783,7 @@ QMenu *MainWindow::createRecentFileMenu()
|
|||
|
||||
QMenu *MainWindow::createProfilesMenu()
|
||||
{
|
||||
QMenu *profilesMenu=new QMenu(tr("Radio Profile"));
|
||||
QMenu *profilesMenu=new QMenu(tr("Radio Profile"), this);
|
||||
int i;
|
||||
for ( i = 0; i < MAX_PROFILES; ++i) {
|
||||
profilesMenu->addAction(profileActs[i]);
|
||||
|
|
|
@ -82,6 +82,10 @@ MdiChild::MdiChild():
|
|||
}
|
||||
}
|
||||
|
||||
MdiChild::~MdiChild() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MdiChild::qSleep(int ms)
|
||||
{
|
||||
if (ms<0)
|
||||
|
|
|
@ -61,6 +61,7 @@ class MdiChild : public QWidget
|
|||
|
||||
public:
|
||||
MdiChild();
|
||||
~MdiChild();
|
||||
|
||||
void newFile();
|
||||
bool loadFile(const QString &fileName, bool resetCurrentFile=true);
|
||||
|
|
|
@ -142,6 +142,7 @@ SimulatorDialogTaranis::~SimulatorDialogTaranis()
|
|||
SimulatorDialog::~SimulatorDialog()
|
||||
{
|
||||
delete timer;
|
||||
if (simulator) delete simulator;
|
||||
}
|
||||
|
||||
void SimulatorDialog::closeEvent (QCloseEvent *)
|
||||
|
|
|
@ -48,6 +48,8 @@ class SimulatorInterface {
|
|||
|
||||
public:
|
||||
|
||||
virtual ~SimulatorInterface() {};
|
||||
|
||||
virtual void start(QByteArray & eeprom, 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