Fix crash if the main window is deleted inside the nested event loop of the context menu

Review Request #114440 - Created Dec. 14, 2013 and discarded

Frank Reininghaus
We get a crash if the main window is deleted while the nested event loop of the context menu is running. The reason is that the KFileItemActions instance is currently a local variable inside a member function of the context menu. After returning from the event loop, the context menu (child of the main window) is deleted, and calling the destructor of KFileItemActions causes trouble.

This can be reproduced by (provided that only one Dolphin window is open)

sleep 5; qdbus `qdbus | grep dolphin` /dolphin/Dolphin_1/actions/file_quit trigger

and then opening the context menu in Dolphin.

The easiest solution seems to be that we make sure that KFileItemActions is destroyed at the same time as the menu, by making it a member of the context menu, rather than a local variable. This is also how it's done in Konqueor's KonqPopupMenu.

I tried to keep the diff as small as possible for the KDE/4.11 branch. There might be some potential for simplifications, but these should better be done in master.
Fixes the crash for me. Context menu still sees to work OK.
Frank Reininghaus
Frank Reininghaus
Review request changed

Status: Discarded