Re: Disappointed by GNUstep

Sergei Golovin <[email protected]> Mon, 07 Feb 2022 17:52:07 +0400
Newsgroups gmane.comp.lib.gnustep.devel
Message-ID <d967cbee1056ab56e4fd579b1a1082d4@iamhere>
On 2022-02-06 22:50:07 +0400 Fred Kiefer <[email protected]> wrote:

> Your change looks great to me, as always. Let's just hope it does not 
> break 
> anything for the other two issues that caused the different changes 
> on that 
> code. 

That one issue in December was due to deallocation of NSPopUpButtonCell
causing to call -[synchronizeTitleAndSelectedItem] followed with 
updating
of the _menuItem, its _menu  and all dependants (validators) where
the segfault occurs because one of the validators has been deallocated 
already.

#0  0x00007ffff6ee9415 in objc_msg_lookup () from 
/usr/lib/x86_64-linux-gnu/libobjc.so.4
#1  0x00007ffff7845af0 in -[NSApplication targetForAction:to:from:] 
(self=0x5555559683a0, _cmd=0x7ffff7c72330 <_OBJC_SELECTOR_TABLE+2384>,
     theAction=0x555555ad8570, theTarget=0x555555e464b0, 
sender=0x555555d1feb0) at NSApplication.m:2294
#2  0x00007ffff7949ca8 in -[NSMenu _autoenableItem:] 
(self=0x555555d1fa40, _cmd=0x7ffff7c723f0 <_OBJC_SELECTOR_TABLE+2576>,
     item=0x555555d1feb0) at NSMenu.m:1184
#3  0x00007ffff794a078 in -[NSMenu update] (self=0x555555d1fa40, 
_cmd=0x7ffff7c721a0 <_OBJC_SELECTOR_TABLE+1984>) at NSMenu.m:1260
#4  0x00007ffff7948f56 in -[NSMenu itemChanged:] (self=0x555555d1fa40, 
_cmd=0x7ffff7c79650 <_OBJC_SELECTOR_TABLE+496>,
     anObject=0x555555d1fdd0) at NSMenu.m:878
#5  0x00007ffff7957bdd in -[NSMenuItem setImage:] 
(self=0x555555d1fdd0, _cmd=0x7ffff7c98cf0 <_OBJC_SELECTOR_TABLE+1168>, 
image=0x0)
     at NSMenuItem.m:375
#6  0x00007ffff797c589 in -[NSPopUpButtonCell setMenuItem:] 
(self=0x555555d1fc60, _cmd=0x7ffff7c98da0 <_OBJC_SELECTOR_TABLE+1344>, 
item=0x0)
     at NSPopUpButtonCell.m:652
#7  0x00007ffff797cf77 in -[NSPopUpButtonCell 
synchronizeTitleAndSelectedItem] (self=0x555555d1fc60,
     _cmd=0x7ffff7c98ac0 <_OBJC_SELECTOR_TABLE+608>) at 
NSPopUpButtonCell.m:854
#8  0x00007ffff797b631 in -[NSPopUpButtonCell setMenu:] 
(self=0x555555d1fc60, _cmd=0x7ffff7c98940 <_OBJC_SELECTOR_TABLE+224>, 
menu=0x0)
     at NSPopUpButtonCell.m:218
#9  0x00007ffff797b284 in -[NSPopUpButtonCell dealloc] 
(self=0x555555d1fc60, _cmd=0x7ffff7534970 <_OBJC_SELECTOR_TABLE+48>)
     at NSPopUpButtonCell.m:153

May be doing that is excessive in the context  of deallocation?

The attached patch changes the -[dealloc] to do the code chunk 
equivalent to -[setMenu:nil]
avoiding that -[NSPopUpButtonCell synchronizeTitleAndSelectedItem] and 
following.

-- 
SG

  <gtam_segfault_on_quit_bug.patch>
gtam_segfault_on_quit_bug.patch (text/x-patch, 789 B)
diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m
index a60a0ca4d..53bb39aae 100644
--- a/Source/NSPopUpButtonCell.m
+++ b/Source/NSPopUpButtonCell.m
@@ -138,6 +138,7 @@ static NSImage *_pbc_image[5];
 
 - (void) dealloc
 {
+  NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
   /* 
    * The popup must be closed here, just in case the cell goes away 
    * while the popup is still displayed. In that case the notification
@@ -150,7 +151,11 @@ static NSImage *_pbc_image[5];
 
   if (_menu != nil)
     {
-      [self setMenu: nil];
+      [_menu _setOwnedByPopUp: nil];
+      [nc removeObserver: self
+                    name: nil
+                  object: _menu];
+      [self setMenuView: nil];
     }
   _selectedItem = nil;
   [super dealloc];