DiagramsWindow: double deletion of m_diagramsTree?

Robert Hairgrove code at roberthairgrove.com
Thu Nov 11 13:55:56 GMT 2021


In the constructor of DiagramsWindow  (file: diagramswindow.cpp at line 
23), the member variable "m_diagramsTree" (QTableView) is set as 
follows:

(31:)    m_diagramsTree = new QTableView;

Then it is set in the DiagramsWindow by calling the "setWidget()" member 
function of QDockWidget, base class of DiagramsWindow:

(41:)    setWidget(m_diagramsTree);

In the member initialization list of DiagramsWindow, the base class is 
properly initialized with the "parent" argument which is a pointer to 
the instance of UMLAppPrivate which is a member variable of UMLApp. In 
the source code of QDockWidget::setWidget(), since m_diagramsTree is 
created parentless, the code calls "setParent()" of the table view with 
the parent of the QDockWidget, which is the instance of UMLAppPrivate 
which creates it. Therefore, the member "m_diagramsTree" will 
automatically be deleted when UMLAppPrivate is deleted, since both are 
descendents of QObject.

Actually, QDockWidget::setWidget() calls 
QDockWidgetLayout::setWidgetForRole() which calls "addChildWidget()" 
which calls "setParent()" on line 928 if the widget argument "w" has no 
parent of its own.
(source: 
https://code.woboq.org/qt5/qtbase/src/widgets/kernel/qlayout.cpp.html#_ZN7QLayout14addChildWidgetEP7QWidget)

However, the destructor of DiagramsWindow deletes this pointer as well, 
leading to a potential double deletion bug (line 50 of file 
"diagramswindow.cpp").

I suspect that cleaning up code like this is going to be a major 
refactoring effort, since there are potentially hundreds of places like 
this in the Umbrello project?


More information about the umbrello-devel mailing list