From bc68cda41df62781c24a5524cbf5398ec34a013d Mon Sep 17 00:00:00 2001 From: Dmitry Kazakov Date: Wed, 23 Nov 2016 09:43:24 +0300 Subject: [PATCH] Don't leak shapes! The recursive crash is finally fixed. --- libs/flake/KoShapeContainer.cpp | 8 +++++++- libs/flake/tests/TestSvgParser.cpp | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/flake/KoShapeContainer.cpp b/libs/flake/KoShapeContainer.cpp index 411098c702..5f9ec1a779 100644 --- a/libs/flake/KoShapeContainer.cpp +++ b/libs/flake/KoShapeContainer.cpp @@ -30,6 +30,7 @@ #include #include "kis_painting_tweaks.h" +#include "kis_assert.h" KoShapeContainerPrivate::KoShapeContainerPrivate(KoShapeContainer *q) : KoShapePrivate(q), @@ -58,9 +59,14 @@ KoShapeContainer::~KoShapeContainer() { Q_D(KoShapeContainer); if (d->model) { - Q_FOREACH (KoShape *shape, d->model->shapes()) { + QList ownedShapes = d->model->shapes(); + + Q_FOREACH (KoShape *shape, ownedShapes) { + shape->setParent(0); delete shape; } + + KIS_SAFE_ASSERT_RECOVER_NOOP(!d->model->count()); } } diff --git a/libs/flake/tests/TestSvgParser.cpp b/libs/flake/tests/TestSvgParser.cpp index c5199faae4..8e01f9ad8b 100644 --- a/libs/flake/tests/TestSvgParser.cpp +++ b/libs/flake/tests/TestSvgParser.cpp @@ -47,6 +47,11 @@ struct SvgTester } + ~SvgTester () + { + qDeleteAll(shapes); + } + void run() { shapes = parser.parseSvg(root, &fragmentSize); } -- GitLab