tst_QTextEdit: fix memleak in the MyPaintDevice helper

The constructor new'ed up a MyPaintEngine, but there was no destructor
to delete the object again. Neither is ownership of the engine
transferred out of the class, so the object was leaked.

Fix by holding it in a unique_ptr.

Amends 391e3aeef45efc937979b44c32147206e389a60b.

Pick-to: 6.8 6.5 5.15
Change-Id: I0c4da10d5a1659eceac0deba32cac757579e46c5
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit de2de7e12cb82064e32197f88c8772ceeeead8ae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-30 19:21:24 +02:00 committed by Qt Cherry-pick Bot
parent 414ca19a3f
commit a8f7a100ae

View File

@ -2782,14 +2782,14 @@ namespace {
class MyPaintDevice : public QPaintDevice
{
public:
MyPaintDevice() : m_paintEngine(new MyPaintEngine)
MyPaintDevice() : m_paintEngine(std::make_unique<MyPaintEngine>())
{
}
QPaintEngine *paintEngine () const override
{
return m_paintEngine;
return m_paintEngine.get();
}
int metric (QPaintDevice::PaintDeviceMetric metric) const override {
@ -2816,7 +2816,7 @@ namespace {
return 0;
}
MyPaintEngine *m_paintEngine;
std::unique_ptr<MyPaintEngine> m_paintEngine;
};
}