[vbox-dev] [PATCH] Fix possible crash when closing VBox Manager UI

Martin Fleisz martin.fleisz at thincast.com
Wed Mar 13 11:17:14 GMT 2019


I found a potential crash that happens when you close the VirtualBox
Manager UI.

According to the Qt documentation QMainWindow::setCentralWidget takes
ownership of the given widget.

In UIVirtualBoxManager::cleanupWidgets we first call setCentralWidget(0)
to deconfigure the widget. Right afterwards we call delete on the
(already freed) widget.

The attached patch removes the (unnecessary) delete and just reset the
widget pointer to 0.

The patch is contributed under the terms of the MIT license.

Cheers, Martin

diff --git
src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp
src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp
index 14515a60db..406ef2034c 100644
--- src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp
+++ src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp
@@ -1540,10 +1540,9 @@ void UIVirtualBoxManager::cleanupConnections()
 
 void UIVirtualBoxManager::cleanupWidgets()
 {
-    /* Deconfigure central-widget: */
+    /* Deconfigure and destroy central-widget: */
     setCentralWidget(0);
-    /* Destroy central-widget: */
-    delete m_pWidget;
+    /* Reset central-widget: */
     m_pWidget = 0;
 }
 




More information about the vbox-dev mailing list