Skip to content

Commit d6ae0e9

Browse files
xingriwebkit-commit-queue
authored andcommitted
[MSE] Move PublicURLManager shutdown logic so ActiveDOMObjects associated with public URLs won't leak.
https://bugs.webkit.org/show_bug.cgi?id=128532 Patch by Byungseon Shin <sun.shin@lge.com> on 2014-02-13 Reviewed by Jer Noble. This fixes a leak of DOM objects by breaking the circular reference between Document, PublicURLManager, and MediaSource. Instead of clearing PublicURLManager at destruction-time, which is delayed indefinitely because of the circular reference, clear the PublicURLManager during ActiveDOMObject::stop(). Frome Blink r151890 by <acolwell@chromium.org> <https://src.chromium.org/viewvc/blink?view=rev&revision=151890> * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): (WebCore::ScriptExecutionContext::publicURLManager): * html/DOMURL.h: * html/PublicURLManager.cpp: (WebCore::PublicURLManager::create): (WebCore::PublicURLManager::PublicURLManager): (WebCore::PublicURLManager::registerURL): (WebCore::PublicURLManager::stop): * html/PublicURLManager.h: Canonical link: https://commits.webkit.org/146827@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 943724a commit d6ae0e9

5 files changed

Lines changed: 57 additions & 11 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
2014-02-13 Byungseon Shin <sun.shin@lge.com>
2+
3+
[MSE] Move PublicURLManager shutdown logic so ActiveDOMObjects associated with public URLs won't leak.
4+
https://bugs.webkit.org/show_bug.cgi?id=128532
5+
6+
Reviewed by Jer Noble.
7+
8+
This fixes a leak of DOM objects by breaking the circular reference
9+
between Document, PublicURLManager, and MediaSource.
10+
Instead of clearing PublicURLManager at destruction-time,
11+
which is delayed indefinitely because of the circular reference,
12+
clear the PublicURLManager during ActiveDOMObject::stop().
13+
14+
Frome Blink r151890 by <acolwell@chromium.org>
15+
<https://src.chromium.org/viewvc/blink?view=rev&revision=151890>
16+
17+
* dom/ScriptExecutionContext.cpp:
18+
(WebCore::ScriptExecutionContext::~ScriptExecutionContext):
19+
(WebCore::ScriptExecutionContext::publicURLManager):
20+
* html/DOMURL.h:
21+
* html/PublicURLManager.cpp:
22+
(WebCore::PublicURLManager::create):
23+
(WebCore::PublicURLManager::PublicURLManager):
24+
(WebCore::PublicURLManager::registerURL):
25+
(WebCore::PublicURLManager::stop):
26+
* html/PublicURLManager.h:
27+
128
2014-02-13 Myles C. Maxfield <mmaxfield@apple.com>
229

330
Remove position:sticky runtime flag

Source/WebCore/dom/ScriptExecutionContext.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ ScriptExecutionContext::~ScriptExecutionContext()
117117
ASSERT((*iter)->scriptExecutionContext() == this);
118118
(*iter)->contextDestroyed();
119119
}
120-
#if ENABLE(BLOB)
121-
if (m_publicURLManager)
122-
m_publicURLManager->contextDestroyed();
123-
#endif
124120
}
125121

126122
void ScriptExecutionContext::processMessagePortMessagesSoon()
@@ -367,7 +363,7 @@ int ScriptExecutionContext::circularSequentialID()
367363
PublicURLManager& ScriptExecutionContext::publicURLManager()
368364
{
369365
if (!m_publicURLManager)
370-
m_publicURLManager = PublicURLManager::create();
366+
m_publicURLManager = PublicURLManager::create(this);
371367
return *m_publicURLManager;
372368
}
373369
#endif

Source/WebCore/html/DOMURL.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class DOMURL : public RefCounted<DOMURL>, public URLUtils<DOMURL> {
5353
void setHref(const String&, ExceptionCode&);
5454

5555
#if ENABLE(BLOB)
56-
static void contextDestroyed(ScriptExecutionContext*);
57-
5856
static String createObjectURL(ScriptExecutionContext*, Blob*);
5957
static void revokeObjectURL(ScriptExecutionContext*, const String&);
6058

Source/WebCore/html/PublicURLManager.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,24 @@
3535

3636
namespace WebCore {
3737

38+
PassOwnPtr<PublicURLManager> PublicURLManager::create(ScriptExecutionContext* context)
39+
{
40+
OwnPtr<PublicURLManager> publicURLManager(adoptPtr(new PublicURLManager(context)));
41+
publicURLManager->suspendIfNeeded();
42+
return publicURLManager.release();
43+
}
44+
45+
PublicURLManager::PublicURLManager(ScriptExecutionContext* context)
46+
: ActiveDOMObject(context)
47+
, m_isStopped(false)
48+
{
49+
}
50+
3851
void PublicURLManager::registerURL(SecurityOrigin* origin, const URL& url, URLRegistrable* registrable)
3952
{
53+
if (m_isStopped)
54+
return;
55+
4056
RegistryURLMap::iterator found = m_registryToURL.add(&registrable->registry(), URLSet()).iterator;
4157
found->key->registerURL(origin, url, registrable);
4258
found->value.add(url.string());
@@ -53,8 +69,12 @@ void PublicURLManager::revoke(const URL& url)
5369
}
5470
}
5571

56-
void PublicURLManager::contextDestroyed()
72+
void PublicURLManager::stop()
5773
{
74+
if (m_isStopped)
75+
return;
76+
77+
m_isStopped = true;
5878
for (RegistryURLMap::iterator i = m_registryToURL.begin(); i != m_registryToURL.end(); ++i) {
5979
for (URLSet::iterator j = i->value.begin(); j != i->value.end(); ++j)
6080
i->key->unregisterURL(URL(ParsedURLString, *j));

Source/WebCore/html/PublicURLManager.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define PublicURLManager_h
2828

2929
#if ENABLE(BLOB)
30+
#include "ActiveDOMObject.h"
3031
#include <wtf/HashMap.h>
3132
#include <wtf/HashSet.h>
3233
#include <wtf/PassOwnPtr.h>
@@ -41,19 +42,23 @@ class SecurityOrigin;
4142
class URLRegistry;
4243
class URLRegistrable;
4344

44-
class PublicURLManager {
45+
class PublicURLManager : public ActiveDOMObject {
4546
WTF_MAKE_FAST_ALLOCATED;
4647
public:
47-
static OwnPtr<PublicURLManager> create() { return adoptPtr(new PublicURLManager); }
48+
static PassOwnPtr<PublicURLManager> create(ScriptExecutionContext*);
4849

4950
void registerURL(SecurityOrigin*, const URL&, URLRegistrable*);
5051
void revoke(const URL&);
51-
void contextDestroyed();
5252

53+
// ActiveDOMObject interface.
54+
virtual void stop() override;
5355
private:
56+
PublicURLManager(ScriptExecutionContext*);
57+
5458
typedef HashSet<String> URLSet;
5559
typedef HashMap<URLRegistry*, URLSet > RegistryURLMap;
5660
RegistryURLMap m_registryToURL;
61+
bool m_isStopped;
5762
};
5863

5964
} // namespace WebCore

0 commit comments

Comments
 (0)