Fix to avoid dangling pointer when changing the menu of a NSPopUpButtonCell

This commit is contained in:
Wolfgang Lux 2022-02-06 15:58:18 +01:00
parent 004c4ce270
commit e4bd00f6eb
2 changed files with 16 additions and 2 deletions

View file

@ -1,3 +1,8 @@
2022-02-06 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSPopUpButtonCell.m: Add fix to avoid a dangling
pointer when changing the menu.
2022-01-11 Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSBundleAdditions.m: Use FOR_IN macro instead

View file

@ -150,8 +150,6 @@ static NSImage *_pbc_image[5];
if (_menu != nil)
{
// prevent further actions on the menu
_pbcFlags.usesItemFromMenu = NO;
[self setMenu: nil];
}
_selectedItem = nil;
@ -178,6 +176,17 @@ static NSImage *_pbc_image[5];
name: nil
object: _menu];
}
if (_selectedItem != nil)
{
// _selectedItem may be dead after the following ASSIGN statement,
// so make sure we leave no dangling pointer behind and unset the
// item's state if necessary.
if (_pbcFlags.altersStateOfSelectedItem)
{
[_selectedItem setState: NSOffState];
}
_selectedItem = nil;
}
ASSIGN(_menu, menu);
if (_menu != nil)
{