Skip to content

Commit

Permalink
Merge pull request #1139 from ivandi69/diagram-memory-leak
Browse files Browse the repository at this point in the history
Plug diagram memory leak
  • Loading branch information
ra3xdh authored Dec 16, 2024
2 parents b0523fa + 03b791f commit f152ee2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
18 changes: 11 additions & 7 deletions qucs/diagrams/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <QDateTime>
#include <QPainter>
#include <QDebug>
#include <QtAlgorithms>

Diagram::Diagram(int _cx, int _cy) {
cx = _cx;
Expand Down Expand Up @@ -93,6 +94,10 @@ Diagram::Diagram(int _cx, int _cy) {
}

Diagram::~Diagram() {
qDeleteAll(Graphs);
qDeleteAll(Arcs);
qDeleteAll(Lines);
qDeleteAll(Texts);
}

/*!
Expand Down Expand Up @@ -846,16 +851,15 @@ int Graph::loadDatFile(const QString &fileName) {

Info.setFile(file);
if (g->lastLoaded.isValid())
if (g->lastLoaded.currentMSecsSinceEpoch() >
Info.lastModified().currentMSecsSinceEpoch()) //Millisecond resulution is needed for tuning
if (g->lastLoaded.toMSecsSinceEpoch() >=
Info.lastModified().toMSecsSinceEpoch()) //Millisecond resulution is needed for tuning
return 1; // dataset unchanged -> no update necessary
qDebug() << "Loading data from " << Info.canonicalFilePath();

qDeleteAll(g->mutable_axes());
g->mutable_axes().clear();
g->countY = 0;
g->mutable_axes().clear(); // HACK
if (g->cPointsY) {
delete[] g->cPointsY;
g->cPointsY = 0;
}
delete[] g->cPointsY;
if (Variable.isEmpty()) return 0;

#if 0 // FIXME encapsulation. implement digital waves later.
Expand Down
2 changes: 2 additions & 0 deletions qucs/diagrams/diagramdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <QHeaderView>
#include <QDir>
#include <QDebug>
#include <QtAlgorithms>

#define CROSS3D_SIZE 30
#define WIDGET3D_SIZE 2*CROSS3D_SIZE
Expand Down Expand Up @@ -1349,6 +1350,7 @@ void DiagramDialog::slotApply()

} // of "if(Diag->Name != "Tab")"

qDeleteAll(Diag->Graphs);
Diag->Graphs.clear(); // delete the graphs

for (std::unique_ptr<Graph>& graph : Graphs) {
Expand Down
3 changes: 2 additions & 1 deletion qucs/diagrams/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QPainter>
#include <QDebug>
#include <QPainterPath>
#include <QtAlgorithms>

class Diagram;

Expand All @@ -47,8 +48,8 @@ Graph::Graph(Diagram const* d, const QString& _Line) :

Graph::~Graph()
{
if(cPointsY != 0)
delete[] cPointsY;
qDeleteAll(cPointsX);
}

// ---------------------------------------------------------------------
Expand Down

0 comments on commit f152ee2

Please sign in to comment.