Assertions and test to catch sub-menu resource problem.

The lifetime of inserted submenus isn't managed properly.
The problem is still present.  This just helps catch it.
Fix sub-menu resource management.

This change fixes the problem by releasing the menu handle if its ownership was 'adopted'. This mutates *all* the copies of the handle to the menu so they all know ownership has been released.
Merge branch 'fix/sub_menu_resource_crash'