[PATCH] user32: Don't depend on HMENU being valid for popup menus

Ken Thomases ken at codeweavers.com
Wed May 7 15:59:07 CDT 2014


On May 7, 2014, at 9:57 AM, Andrew Eikum wrote:

> On Wed, May 07, 2014 at 06:09:44AM -0500, Ken Thomases wrote:
>> On May 6, 2014, at 9:28 AM, Andrew Eikum wrote:
>> 
>>> +static HMENU MENU_GetHandle(POPUPMENU *menu)
>>> +{
>>> +    return menu ? menu->obj.handle : NULL;
>>> +}
>> 
>> Now that DestroyMenu() really destroys the handle, any use of the
>> handle and thus this function has to be examined very carefully.  The
>> menu pointer may be valid and menu->obj.handle may have a value, but
>> that value may no longer be a valid handle.
>> 
> 
> Unless I'm mistaken, these issues existed before this patch as well.
> DestroyMenu has always closed the handle, and additionally destroyed
> the struct. Now we preserve the struct if it's referenced by another
> menu.

Well, first of all, the situation before this patch has problems because of that, which is what you're trying to solve.

Also, the specific issue of having the struct and going from that to the handle, which might not be valid, and then implicitly expecting to be able to get back to the struct is new.

> There is some precedent for Windows returning an invalid HMENU. See
> the second GetMenuItemInfoA call in test_subpopup_locked_by_menu which
> returns the handle of the submenu that was just destroyed.

Yes.  I'm just not sure if that's what happens in these particular circumstances.  And I'm not so terribly concerned about the handle being passed out to other code being invalid, although it would be good to know we're doing the right thing.  It's mostly about places where the code has the menu pointer, obtains the menu handle from it, passes that to other code in the menu module, and then tries to get the menu pointer again.

-Ken




More information about the wine-devel mailing list