<rdar://problem/6684745> Crash in -[WebView removeSizeObservers] when loading NIB...
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2009 03:10:29 +0000 (03:10 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2009 03:10:29 +0000 (03:10 +0000)
Reviewed by Dan Bernstein and Timothy Hatcher.

The implementation of -[NSView initWithCoder:] can result in -viewWillMoveToSuperview:/-viewDidMoveToSuperview: being sent to
our view before we've had a chance to initialize _private, so we need to ensure it is non-nil before dereferencing it in those
methods.

* WebView/WebView.mm:
(-[WebView removeSizeObservers]): Nil-check _private before dereferencing it.
(-[WebView addSizeObservers]): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@42196 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/mac/ChangeLog
WebKit/mac/WebView/WebView.mm

index fe70071..9be9a48 100644 (file)
@@ -1,3 +1,17 @@
+2009-04-02  Mark Rowe  <mrowe@apple.com>
+
+        Reviewed by Dan Bernstein and Timothy Hatcher.
+
+        <rdar://problem/6684745> Crash in -[WebView removeSizeObservers] when loading NIB file
+
+        The implementation of -[NSView initWithCoder:] can result in -viewWillMoveToSuperview:/-viewDidMoveToSuperview: being sent to
+        our view before we've had a chance to initialize _private, so we need to ensure it is non-nil before dereferencing it in those
+        methods.
+
+        * WebView/WebView.mm:
+        (-[WebView removeSizeObservers]): Nil-check _private before dereferencing it.
+        (-[WebView addSizeObservers]): Ditto.
+
 2009-04-02  Adele Peterson  <adele@apple.com>
 
         Reviewed by Darin Adler.
index 8acb9f8..5a922e5 100644 (file)
@@ -2561,7 +2561,9 @@ static bool needsWebViewInitThreadWorkaround()
 
 - (void)removeSizeObservers
 {
-    if (!_private->useDocumentViews && [self window]) {
+    // -removeSizeObservers can be called from -viewWillMoveToSuperview: below -[NSView initWithCoder:], before
+    // we've had a chance to initialize _private
+    if (_private && !_private->useDocumentViews && [self window]) {
         [[NSNotificationCenter defaultCenter] removeObserver:self
             name:NSViewFrameDidChangeNotification object:self];
         [[NSNotificationCenter defaultCenter] removeObserver:self
@@ -2571,7 +2573,9 @@ static bool needsWebViewInitThreadWorkaround()
 
 - (void)addSizeObservers
 {
-    if (!_private->useDocumentViews && [self window]) {
+    // -addSizeObservers can be called from -viewDidMoveToSuperview: below -[NSView initWithCoder:], before
+    // we've had a chance to initialize _private
+    if (_private && !_private->useDocumentViews && [self window]) {
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_boundsChanged) 
             name:NSViewFrameDidChangeNotification object:self];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_boundsChanged)