Fix critical QWidgetItem memory leak in ensureWidgetContainsEmptyGridLayout

Address sanitizer detected a 1056-byte memory leak in QWidgetItem objects.
This was the actual root cause of the leak reported in the stack trace.

Problem: In ensureWidgetContainsEmptyGridLayout(), when clearing existing
layouts, the code was calling layout->takeAt(0) to remove QLayoutItem
objects but never deleting them. This caused QWidgetItem objects to
accumulate in memory without ever being freed.

The takeAt() method removes items from the layout but does NOT delete them.
The caller is responsible for deleting the returned QLayoutItem objects.

Fix: Added `delete item;` in the cleanup loop to properly free QWidgetItem
objects when clearing layouts before rebuilding the UI.
This commit is contained in:
Kristian Bendiksen committed 2025-09-04 09:04:30 +02:00
1 parent 2f4f97c80b
commit 25dd9db293
1 file changed
+1
@@ -454,6 +454,7 @@ void caf::PdmUiFormLayoutObjectEditor::ensureWidgetContainsEmptyGridLayout( QWid
QLayoutItem* item;
while ( ( item = layout->takeAt( 0 ) ) != 0 )
{
delete item;
}
QWidget().setLayout( layout );
}