Skip to content

Commit 15bc2f9

Browse files
author
beidson
committed
Reviewed by Maciej
Plugged a leak in StringImpl::replace() * platform/StringImpl.cpp: (WebCore::StringImpl::replace): Canonical link: https://commits.webkit.org/13461@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16065 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent e6029b1 commit 15bc2f9

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

WebCore/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2006-08-27 Brady Eidson <beidson@apple.com>
2+
3+
Reviewed by Maciej
4+
5+
Plugged a leak in StringImpl::replace()
6+
7+
* platform/StringImpl.cpp:
8+
(WebCore::StringImpl::replace):
9+
110
2006-08-27 Nikolas Zimmermann <zimmermann@kde.org>
211

312
Reviewed and landed by Anders.

WebCore/platform/StringImpl.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,12 +762,16 @@ StringImpl* StringImpl::replace(UChar pattern, const StringImpl* str)
762762
{
763763
int slen = str ? str->length() : 0;
764764
int index = 0;
765-
StringImpl* result = this;
766-
while ((index = result->find(pattern, index)) >= 0) {
767-
result = result->replace(index, 1, str);
765+
StringImpl* oldResult = this;
766+
StringImpl* newResult;
767+
while ((index = oldResult->find(pattern, index)) >= 0) {
768+
newResult = oldResult->replace(index, 1, str);
769+
if (oldResult != this)
770+
delete oldResult;
771+
oldResult = newResult;
768772
index += slen;
769773
}
770-
return result;
774+
return oldResult;
771775
}
772776

773777
bool equal(const StringImpl* a, const StringImpl* b)

0 commit comments

Comments
 (0)