Bug 376693

Summary: QAction objects passed to ContextMenuExtension are leaked
Product: [Developer tools] kdevplatform Reporter: Friedrich W. H. Kossebau <kossebau>
Component: generalAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: git master   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 5.2.0
Sentry Crash Report:

Description Friedrich W. H. Kossebau 2017-02-20 02:00:30 UTC
Many plugins create QAction objects on the fly in their implementation of the IPlugin::contextMenuExtension() method and then pass on those inside the returned ContextMenuExtension and forget about them. Just, as the ownership is not specified, callers of the IPlugin::contextMenuExtension() API do not take lifetime responsibility themselves for the QAction objects (and QMenu objects).

With noone caring... objects are leaking and accumulating.

On a first look I could not find a simple solution, so for now noting here.

Things to consider:
* Some plugins also pass existing QAction items which are in used elsewhere, e.g. in the toplevel menu. So simply deleting any QAction objects on destruction of the ContextMenuExtension instance does not work. Might work to just delete objects without a parent.
* More, ContextMenuExtension is currently passed by value and is not explicitely sharing data, so there are many copies of the lists with the pointers to the QAction objects
* The menus filled by the ContextMenuExtension in the API users might have a longer lifetime than the ContextMenuExtension objects, that needs some work as well.