Reviewed by Maciej
authorbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 27 Aug 2006 22:57:38 +0000 (22:57 +0000)
committerbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 27 Aug 2006 22:57:38 +0000 (22:57 +0000)
        Plugged a leak in StringImpl::replace()

        * platform/StringImpl.cpp:
        (WebCore::StringImpl::replace):

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

WebCore/ChangeLog
WebCore/platform/StringImpl.cpp

index a5ffa89dbb0862ee2eb6e225218d3b7f0eeca555..332052cde13a62f1e46211661717e3f019017635 100644 (file)
@@ -1,3 +1,12 @@
+2006-08-27  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Maciej
+
+        Plugged a leak in StringImpl::replace()
+
+        * platform/StringImpl.cpp:
+        (WebCore::StringImpl::replace):
+
 2006-08-27  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed and landed by Anders.
index 83c2a748a113c65210b2a81b9562e1138b1638e6..cfb075c0b200872fde4adb50a929434b3591e022 100644 (file)
@@ -762,12 +762,16 @@ StringImpl* StringImpl::replace(UChar pattern, const StringImpl* str)
 {
     int slen = str ? str->length() : 0;
     int index = 0;
-    StringImpl* result = this;
-    while ((index = result->find(pattern, index)) >= 0) {
-        result = result->replace(index, 1, str);
+    StringImpl* oldResult = this;
+    StringImpl* newResult;
+    while ((index = oldResult->find(pattern, index)) >= 0) {
+        newResult = oldResult->replace(index, 1, str);
+        if (oldResult != this)
+            delete oldResult;
+        oldResult = newResult;
         index += slen;
     }
-    return result;
+    return oldResult;
 }
 
 bool equal(const StringImpl* a, const StringImpl* b)