:fix valgrind issues

This commit is contained in:
Jan Käberich 2022-04-23 16:18:21 +02:00
parent f29f62c3f7
commit 53dcff8745
4 changed files with 25 additions and 4 deletions

View File

@ -150,6 +150,7 @@ static constexpr Protocol::DeviceStatusV1 defaultStatusV1 = {
Device::Device(QString serial)
{
info = defaultInfo;
status = {};
m_handle = nullptr;
infoValid = false;

View File

@ -281,13 +281,13 @@ void AppWindow::closeEvent(QCloseEvent *event)
for(auto m : Mode::getModes()) {
m->shutdown();
}
delete device;
QSettings settings;
settings.setValue("geometry", saveGeometry());
// deactivate currently used mode (stores mode state in settings)
if(Mode::getActiveMode()) {
Mode::getActiveMode()->deactivate();
}
delete device;
pref.store();
QMainWindow::closeEvent(event);
}

View File

@ -96,6 +96,22 @@ void SCPI::input(QString line)
}
}
SCPINode::~SCPINode()
{
if(parent) {
parent->remove(this);
}
while(commands.size() > 0) {
delete commands.front();
commands.erase(commands.begin());
}
while(subnodes.size() > 0) {
auto node = subnodes.front();
remove(node);
delete node;
}
}
bool SCPINode::add(SCPINode *node)
{
if(nameCollision(node->name)) {
@ -103,6 +119,7 @@ bool SCPINode::add(SCPINode *node)
return false;
}
subnodes.push_back(node);
node->parent = this;
return true;
}
@ -111,6 +128,7 @@ bool SCPINode::remove(SCPINode *node)
auto it = std::find(subnodes.begin(), subnodes.end(), node);
if(it != subnodes.end()) {
subnodes.erase(it);
node->parent = nullptr;
return true;
} else {
return false;

View File

@ -16,8 +16,8 @@ public:
QString execute(QStringList params);
QString query(QStringList params);
QString name() {return _name;}
bool queryable() { return fn_query != nullptr;};
bool executable() { return fn_cmd != nullptr;};
bool queryable() { return fn_query != nullptr;}
bool executable() { return fn_cmd != nullptr;}
private:
const QString _name;
std::function<QString(QStringList)> fn_cmd;
@ -28,7 +28,8 @@ class SCPINode {
friend class SCPI;
public:
SCPINode(QString name) :
name(name){}
name(name), parent(nullptr){}
~SCPINode();
bool add(SCPINode *node);
bool remove(SCPINode *node);
@ -41,6 +42,7 @@ private:
const QString name;
std::vector<SCPINode*> subnodes;
std::vector<SCPICommand*> commands;
SCPINode *parent;
};
class SCPI : public QObject, public SCPINode