Skip to content


Browse files Browse the repository at this point in the history
Swap two method calls to prevent a crash with the 10.12 SDK (#2609)
With this change we no longer KVObserve an object we aren’t interested in anymore and the -tabView:didCloseTabViewItem: method actually matches its name now (before it was more of a tabView:willCloseTabViewItem: method).

Normally the tab bar cell observes its delegate’s (SPDatabaseDocument) isProcessing property. Changes to this will trigger an async redraw of the tab view. The redrawing itself may involve a timer and a call to the tab view delegate (SPWindowController). Now, when the window is being closed this would cause the connection to close, which would affect the isProcessing property. However this time, when the timer is being fired the window controller would already be dealloc’d (since the tab bar delegate is unretained) causing a use-after-free crash.
Previously -[PSMTabBarControl viewWillMoveToWindow:] stepped in at the right time and killed the timer before it could fire but on 10.12 the calls have shifted so the timer actually gets to fire and crash.
This change solves the issue by not even letting the tab bar come to the point where it creates the problematic timer.
  • Loading branch information
dmoagx committed Nov 4, 2016
1 parent f77f871 commit 013fff3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Frameworks/PSMTabBar/PSMTabBarControl.m
Expand Up @@ -1912,11 +1912,14 @@ - (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)aTabView
while ( (cell = [e nextObject]) ) {
//remove the observer binding
if ([cell representedObject] && ![tabItems containsObject:[cell representedObject]]) {
// see issue #2609
// -removeTabForCell: comes first to stop the observing that would be triggered in the delegate's call tree
// below and finally caused a crash.
[self removeTabForCell:cell];

if ([[self delegate] respondsToSelector:@selector(tabView:didCloseTabViewItem:)]) {
[[self delegate] tabView:aTabView didCloseTabViewItem:[cell representedObject]];

[self removeTabForCell:cell];

Expand Down

0 comments on commit 013fff3

Please sign in to comment.