REGRESSION (r258525): Leak of NSMutableAttributedString in -[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]
<https://webkit.org/b/209932>
<rdar://problem/61228565>

Reviewed by Chris Fleizach.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):
Move early return to avoid leaking NSMutableAttributedString.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259428 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 5941298..0a0526d8 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,15 @@
+2020-04-02  David Kilzer  <ddkilzer@apple.com>
+
+        REGRESSION (r258525): Leak of NSMutableAttributedString in -[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]
+        <https://webkit.org/b/209932>
+        <rdar://problem/61228565>
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+        (-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]):
+        Move early return to avoid leaking NSMutableAttributedString.
+
 2020-04-02  Chris Dumez  <cdumez@apple.com>
 
         ActiveDOMObject::hasPendingActivity() should stop preventing wrapper collection after ActiveDOMObject::stop() has been called
diff --git a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm b/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
index 88f8948..fc953b1 100644
--- a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
+++ b/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
@@ -1253,9 +1253,9 @@
             return nil;
 
         RefPtr<Range> range = [protectedSelf rangeForTextMarkerRange:textMarkerRange];
-        NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init];
         if (!range)
             return nil;
+        NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init];
         TextIterator it(*range);
         while (!it.atEnd()) {
             Node& node = it.range().start.container;