mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 14:40:26 -05:00
Fix QProxyStyle memory leak in PdmUiTreeViewStyle creation
Address sanitizer detected a memory leak in QProxyStyle objects created during GUI theme updates. Problem: The updateGuiTheme() function was called multiple times (e.g., during initialization) and repeatedly created new PdmUiTreeViewStyle objects for every PdmUiTreeViewWidget without checking if the widget already had the correct style set. Root cause: Each call to updateGuiTheme() would: 1. Iterate through ALL widgets in the application 2. Create a new PdmUiTreeViewStyle for every tree view widget 3. Call setStyle() which should take ownership, but repeated calls were causing memory leaks Fix: Added a check to only create and set a new PdmUiTreeViewStyle if the widget doesn't already have one. This prevents repeatedly creating new styles for the same widgets during multiple theme update calls. The fix uses dynamic_cast to check if the current style is already a PdmUiTreeViewStyle before creating a new one.
This commit is contained in:
1 parent
25dd9db293
commit
89e940b1ea
1 file changed
+6
-1
@@ -360,7 +360,12 @@ void RiuGuiTheme::updateGuiTheme( RiaDefines::ThemeEnum theme )
|
||||
widget->style()->polish( widget );
|
||||
if ( caf::PdmUiTreeViewWidget* treeViewWidget = dynamic_cast<caf::PdmUiTreeViewWidget*>( widget ) )
|
||||
{
|
||||
treeViewWidget->setStyle( new caf::PdmUiTreeViewStyle );
|
||||
// Only set a new style if the widget doesn't already have a PdmUiTreeViewStyle
|
||||
// to prevent memory leaks from repeatedly creating new styles
|
||||
if ( !dynamic_cast<caf::PdmUiTreeViewStyle*>( treeViewWidget->style() ) )
|
||||
{
|
||||
treeViewWidget->setStyle( new caf::PdmUiTreeViewStyle );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user