From 3b8a5859f873a384feec4a8196b24e407e6a80d8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 24 Mar 2025 16:11:07 +0100 Subject: [PATCH] tst_QGraphicsEffectSource: fix memleak in pixmapPadding() The test function didn't delete the heap-allocated QGraphicsScene, because, a comment indicated, there was some "corruption in scene destruction". Fix the memleak by creating the scene object on the stack. A local asan+ubsan build is clean, and so is a valgrind run, so whatever it was, it seems fixed by now. Amends the start of the public history. Picking back to verify that it's been, indeed, fixed in all active branches. Pick-to: 6.8 6.5 5.15 Change-Id: Ic7f96c7195d58ccbff45b17f76fb2babd1c1b648 Reviewed-by: Axel Spoerl Reviewed-by: Friedemann Kleint (cherry picked from commit 429338154540f92a3efdbe8813a41f98dddeaa08) Reviewed-by: Qt Cherry-pick Bot --- .../tst_qgraphicseffectsource.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp index 28c439dbcd2..b922ec81f86 100644 --- a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp @@ -351,10 +351,10 @@ void tst_QGraphicsEffectSource::pixmapPadding() QPixmap pm(10, 10); pm.fill(Qt::red); - QGraphicsScene *scene = new QGraphicsScene(); - PaddingEffect *effect = new PaddingEffect(scene); + QGraphicsScene scene; + PaddingEffect *effect = new PaddingEffect(&scene); QGraphicsPixmapItem *pmItem = new QGraphicsPixmapItem(pm); - scene->addItem(pmItem); + scene.addItem(pmItem); pmItem->setGraphicsEffect(effect); QFETCH(int, coordinateMode); @@ -366,14 +366,11 @@ void tst_QGraphicsEffectSource::pixmapPadding() effect->padMode = (QGraphicsEffect::PixmapPadMode) padMode; effect->coordinateMode = (Qt::CoordinateSystem) coordinateMode; - scene->render(&dummyPainter, scene->itemsBoundingRect(), scene->itemsBoundingRect()); + scene.render(&dummyPainter, scene.itemsBoundingRect(), scene.itemsBoundingRect()); QCOMPARE(effect->pix.size(), size); QCOMPARE(effect->offset, offset); QCOMPARE(effect->pix.toImage().pixel(0, 0), ulPixel); - - // ### Fix corruption in scene destruction, then enable... - // delete scene; } QTEST_MAIN(tst_QGraphicsEffectSource)