summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-11-22 16:02:50 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-11-23 22:45:28 +0000
commitc4748f909c2de24b49e9867cfc50b03fc168db6a (patch)
treeec6b60339da9dc6c0c85b9ee8d280731cea5b9d9
parente2c0cc9bb3782972147e86eb9d1d26e61ba48a24 (diff)
QStackedLayout: fix a memory leak
A layout takes ownership of the QLayoutItem passed to addItem. Change-Id: Iea3c64453f3cbf4f1b5660e505c1a35dca537833 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 1fcc882d7ca564f17e49b8d51adc43eb5b97c57b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/widgets/kernel/qstackedlayout.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp
index 7430d833db..0b1641c141 100644
--- a/src/widgets/kernel/qstackedlayout.cpp
+++ b/src/widgets/kernel/qstackedlayout.cpp
@@ -44,6 +44,8 @@
#include "private/qwidget_p.h"
#include "private/qlayoutengine_p.h"
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QStackedLayoutPrivate : public QLayoutPrivate
@@ -421,13 +423,13 @@ int QStackedLayout::count() const
*/
void QStackedLayout::addItem(QLayoutItem *item)
{
+ std::unique_ptr<QLayoutItem> guard(item);
QWidget *widget = item->widget();
if (Q_UNLIKELY(!widget)) {
qWarning("QStackedLayout::addItem: Only widgets can be added");
return;
}
addWidget(widget);
- delete item;
}
/*!