<menu> is closed when save_treeview_foreach_func is called for the item following the submenu, so, <menu> is never closed if there isn't any item after the submenu.
Created attachment 504 possible fix quick patch
your patch is correct, i had the same problem in xfburn but didn't think about taking a look into the menueditor code patch applied with revision 21992