Skip to content

Commit 9a1f769

Browse files
authored
Merge pull request #1114 from iakov/fix/memleak_commands
Fix memory access issues
2 parents b830937 + 4c5c0f6 commit 9a1f769

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

plugins/robots/common/twoDModel/src/engine/view/twoDModelWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ QList<AbstractItem *> TwoDModelWidget::selectedColorItems() const
558558

559559
void TwoDModelWidget::onSelectionChange()
560560
{
561-
if (mScene->oneRobot()) {
561+
if (!mScene || mScene->oneRobot()) {
562562
return;
563563
}
564564

qrgui/controller/commands/abstractCommand.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@
2020
using namespace qReal::commands;
2121

2222
AbstractCommand::AbstractCommand()
23-
: mExecuted(false), mRedoEnabled(true), mUndoEnabled(true)
2423
{
2524
mTimestamp = QDateTime::currentMSecsSinceEpoch();
2625
}
2726

2827
AbstractCommand::~AbstractCommand()
2928
{
30-
for (AbstractCommand *command : mPreActions) {
31-
delete command;
32-
}
33-
for (AbstractCommand *command : mPostActions) {
34-
delete command;
35-
}
29+
qDeleteAll(mPreActions);
30+
qDeleteAll(mPostActions);
3631
}
3732

3833
void AbstractCommand::redo()

qrgui/controller/commands/abstractCommand.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class QRGUI_CONTROLLER_EXPORT AbstractCommand : public QObject, public QUndoComm
9292

9393
void removeDuplicatesOn(QList<AbstractCommand *> &list);
9494

95-
bool mExecuted;
96-
bool mRedoEnabled;
97-
bool mUndoEnabled;
98-
QList<AbstractCommand *> mPreActions;
99-
QList<AbstractCommand *> mPostActions;
95+
bool mExecuted { false };
96+
bool mRedoEnabled { true };
97+
bool mUndoEnabled { true };
98+
QList<AbstractCommand *> mPreActions; // has ownership
99+
QList<AbstractCommand *> mPostActions; // has ownership
100100
QString mModuleBinded;
101-
uint mTimestamp;
101+
uint mTimestamp {};
102102
};
103103

104104
inline bool operator==(const AbstractCommand &c1, const AbstractCommand &c2)

qrgui/editor/nodeElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,6 @@ void NodeElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
626626
}
627627

628628
EditorViewScene *evScene = dynamic_cast<EditorViewScene *>(scene());
629-
commands::InsertIntoEdgeCommand *insertCommand = new commands::InsertIntoEdgeCommand(
630-
*evScene, mModels, id(), id(), Id::rootId(), event->scenePos(), boundingRect().bottomRight(), false);
631629

632630
bool shouldProcessResize = true;
633631

@@ -677,6 +675,8 @@ void NodeElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
677675
}
678676

679677
if (shouldProcessResize && mResizeCommand) {
678+
auto *insertCommand = new commands::InsertIntoEdgeCommand(
679+
*evScene, mModels, id(), id(), Id::rootId(), event->scenePos(), boundingRect().bottomRight(), false);
680680
mResizeCommand->addPostAction(insertCommand);
681681
endResize();
682682
}

0 commit comments

Comments
 (0)