Fix potential leak of QPropertyAnimation in QLineEditIconButton

When startOpacityAnimation is triggered and the animation doesn't
finish, it might get leaked during shutdown as shown by valgrind:

```
==133963== 600 (16 direct, 584 indirect) bytes in 1 blocks are definitely lost in loss record 2,326 of 2,356
==133963==    at 0x4841FA3: operator new(unsigned long) (vg_replace_malloc.c:483)
==133963==    by 0x12698E2D: QLineEditIconButton::startOpacityAnimation(double) (qlineedit_p.cpp:437)
==133963==    by 0x1269900D: displayWidgets(std::vector<QLineEditPrivate::SideWidgetEntry, std::allocator<QLineEditPrivate::SideWidgetEntry> > const&, bool) (qlineedit_p.cpp:459)
==133963==    by 0x126A1084: QLineEdit::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_qlineedit.cpp:276)
==133963==    by 0x152D781E: void doActivate<false>(QObject*, int, void**) (qobject.cpp:3935)
==133963==    by 0x1269AB01: QLineEdit::textChanged(QString const&) (moc_qlineedit.cpp:447)
==133963==    by 0x126A0EF8: QLineEdit::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_qlineedit.cpp:255)
==133963==    by 0x152D781E: void doActivate<false>(QObject*, int, void**) (qobject.cpp:3935)
==133963==    by 0x126A1A94: QWidgetLineControl::textChanged(QString const&) (moc_qwidgetlinecontrol_p.cpp:273)
==133963==    by 0x126A4C35: QWidgetLineControl::finishChange(int, bool, bool) (qwidgetlinecontrol.cpp:736)
==133963==    by 0x126A4F05: QWidgetLineControl::internalSetText(QString const&, int, bool) (qwidgetlinecontrol.cpp:772)
==133963==    by 0x12698AF4: setText (qwidgetlinecontrol_p.h:251)
==133963==    by 0x12698AF4: QLineEditPrivate::setText(QString const&) (qlineedit_p.cpp:277)
```

Note that the line numbers above are potentially slightly off as that
backtrace was recorded on Qt 5.15.9.

Pick-to: 6.6 6.5 6.2 5.15
Change-Id: Ie79744d98d2783e4644e18ec51892c0bc43c1557
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 76845e1d31a61735a0f0261fbc15ed7ea5ff71dc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Milian Wolff 2024-01-04 12:19:08 +01:00 committed by Qt Cherry-pick Bot
parent 5981ceb865
commit 45f5991e60

View File

@ -432,7 +432,7 @@ void QLineEditIconButton::animateShow(bool visible)
void QLineEditIconButton::startOpacityAnimation(qreal endValue)
{
QPropertyAnimation *animation = new QPropertyAnimation(this, QByteArrayLiteral("opacity"));
QPropertyAnimation *animation = new QPropertyAnimation(this, QByteArrayLiteral("opacity"), this);
connect(animation, &QPropertyAnimation::finished, this, &QLineEditIconButton::onAnimationFinished);
animation->setDuration(160);