Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plug diagram memory leak #1139

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading