diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp
index 27c803b43d786de212de39f27d2650d02d2a2f7d..751a16c59d914bcc407e34ee685d9830a558628f 100644
--- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp
+++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp
@@ -104,6 +104,7 @@ public:
     tst_QMainWindow();
 
 private slots:
+    void cleanup();
     void getSetCheck();
     void constructor();
     void iconSize();
@@ -147,6 +148,12 @@ private slots:
     void QTBUG21378_animationFinished();
 };
 
+
+void tst_QMainWindow::cleanup()
+{
+    QVERIFY(QApplication::topLevelWidgets().isEmpty());
+}
+
 // Testing get/set functions
 void tst_QMainWindow::getSetCheck()
 {
@@ -854,6 +861,7 @@ void tst_QMainWindow::takeCentralWidget() {
 
     QVERIFY(!w2.isNull());
     QCOMPARE(w2.data(), hopefullyW2);
+    delete w2;
 }
 
 void tst_QMainWindow::corner()