From d41fbea2ba84959dd860f2a9c651e7eea260b008 Mon Sep 17 00:00:00 2001 From: Jian Liang Date: Fri, 11 Jan 2013 13:50:58 +0800 Subject: Fix memory leak in windows vista style Introduce a function named deleteClonedAnimationStyleOption() in qwindowsvistastyle.cpp to delete style option cloned by clonedAnimationStyleOption() to prevent object leak which is hold by the actual style option object. Change-Id: I1afd95ddab237059ce3460ac0b52a65de102eaa5 Reviewed-by: Joerg Bornemann Reviewed-by: Friedemann Kleint --- src/widgets/styles/qwindowsvistastyle.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/widgets/styles/qwindowsvistastyle.cpp') diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 34fddde604..685b328a67 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -181,6 +181,24 @@ QStyleOption *clonedAnimationStyleOption(const QStyleOption*option) { return styleOption; } +/* \internal + Used by animations to delete cloned styleoption +*/ +void deleteClonedAnimationStyleOption(const QStyleOption *option) +{ + if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) + delete slider; + else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast(option)) + delete spinbox; + else if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast(option)) + delete groupBox; + else if (const QStyleOptionComboBox *combo = qstyleoption_cast(option)) + delete combo; + else if (const QStyleOptionButton *button = qstyleoption_cast(option)) + delete button; + else + delete option; +} /*! \class QWindowsVistaStyle @@ -411,7 +429,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt } t->setStartTime(QTime::currentTime()); - delete styleOption; + deleteClonedAnimationStyleOption(styleOption); d->startAnimation(t); } styleObject->setProperty("_q_no_animation", false); @@ -940,7 +958,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption t->setStartTime(QTime::currentTime()); styleObject->setProperty("_q_no_animation", false); - delete styleOption; + deleteClonedAnimationStyleOption(styleOption); d->startAnimation(t); } @@ -1627,7 +1645,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle else t->setDuration(500); - delete styleOption; + deleteClonedAnimationStyleOption(styleOption); d->startAnimation(t); } if (QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject))) { -- cgit v1.2.3