mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 14:40:26 -05:00
Address sanitizer detected a memory leak in CmdFeatureMenuBuilder::MenuItem objects allocated during context menu creation. Problem: The RiuContextMenuLauncher constructor was creating a temporary CmdFeatureMenuBuilder object, populating it with menu items, then copying the entire object to the member variable m_menuBuilder. This caused unnecessary memory allocation and copying of std::vector<MenuItem> data. Root cause: Inefficient constructor implementation: caf::CmdFeatureMenuBuilder menuBuilder; // temp object for (cmd : commandIds) menuBuilder << cmd; // populate temp m_menuBuilder = menuBuilder; // copy entire vector (leak source) Fix: Build the menu directly into the member variable instead of creating a temporary object and copying it: for (cmd : commandIds) m_menuBuilder << cmd; // direct construction This eliminates the unnecessary temporary object creation and copy operation that was causing the MenuItem vector allocation detected by the sanitizer. The fix maintains identical functionality while being more efficient.