- Revision
- 182539
- Author
- [email protected]
- Date
- 2015-04-08 08:59:06 -0700 (Wed, 08 Apr 2015)
Log Message
Merge r182537 - [GTK] Crash in DOMObjectCache when a wrapped object owned by the cache is unreffed by the user
https://bugs.webkit.org/show_bug.cgi?id=143521
Reviewed by Martin Robinson.
This is a case we claim to support, but it only works if the
object has only one reference. In that case, when the user unrefs
it, the weak ref notify callback removes the object from the
cache. However, if the object has more than one ref, the cache
doesn't know the user unreffed it, and when clearing the cache we
try to remove more references than what the object actually has,
causing a crash in g_object_unref.
* bindings/gobject/DOMObjectCache.cpp:
(WebKit::DOMObjectCacheData::clearObject):
Modified Paths
Diff
Modified: releases/WebKitGTK/webkit-2.6/Source/WebCore/ChangeLog (182538 => 182539)
--- releases/WebKitGTK/webkit-2.6/Source/WebCore/ChangeLog 2015-04-08 15:54:49 UTC (rev 182538)
+++ releases/WebKitGTK/webkit-2.6/Source/WebCore/ChangeLog 2015-04-08 15:59:06 UTC (rev 182539)
@@ -1,3 +1,21 @@
+2015-04-08 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Crash in DOMObjectCache when a wrapped object owned by the cache is unreffed by the user
+ https://bugs.webkit.org/show_bug.cgi?id=143521
+
+ Reviewed by Martin Robinson.
+
+ This is a case we claim to support, but it only works if the
+ object has only one reference. In that case, when the user unrefs
+ it, the weak ref notify callback removes the object from the
+ cache. However, if the object has more than one ref, the cache
+ doesn't know the user unreffed it, and when clearing the cache we
+ try to remove more references than what the object actually has,
+ causing a crash in g_object_unref.
+
+ * bindings/gobject/DOMObjectCache.cpp:
+ (WebKit::DOMObjectCacheData::clearObject):
+
2015-02-17 Carlos Garcia Campos <[email protected]>
Use HashMap::add instead of get/contains + set in DOMObjectCache
Modified: releases/WebKitGTK/webkit-2.6/Source/WebCore/bindings/gobject/DOMObjectCache.cpp (182538 => 182539)
--- releases/WebKitGTK/webkit-2.6/Source/WebCore/bindings/gobject/DOMObjectCache.cpp 2015-04-08 15:54:49 UTC (rev 182538)
+++ releases/WebKitGTK/webkit-2.6/Source/WebCore/bindings/gobject/DOMObjectCache.cpp 2015-04-08 15:59:06 UTC (rev 182539)
@@ -43,7 +43,11 @@
{
ASSERT(object);
ASSERT(cacheReferences >= 1);
+ ASSERT(object->ref_count >= 1);
+ // Make sure we don't unref more than the references the object actually has. It can happen that user
+ // unreffed a reference owned by the cache.
+ cacheReferences = std::min(static_cast<unsigned>(object->ref_count), cacheReferences);
GRefPtr<GObject> protect(object);
do {
g_object_unref(object);
Modified: releases/WebKitGTK/webkit-2.6/Tools/ChangeLog (182538 => 182539)
--- releases/WebKitGTK/webkit-2.6/Tools/ChangeLog 2015-04-08 15:54:49 UTC (rev 182538)
+++ releases/WebKitGTK/webkit-2.6/Tools/ChangeLog 2015-04-08 15:59:06 UTC (rev 182539)
@@ -1,3 +1,22 @@
+2015-04-08 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Crash in DOMObjectCache when a wrapped object owned by the cache is unreffed by the user
+ https://bugs.webkit.org/show_bug.cgi?id=143521
+
+ Reviewed by Martin Robinson.
+
+ Add a way to detect unexpected web process crashes to WebViewTest,
+ and a test case to testDOMCache to trigger the crash.
+
+ * TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp:
+ (WebKitDOMNodeTest::testDOMCache):
+ * TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp:
+ (testWebKitWebViewProcessCrashed):
+ * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+ (WebViewTest::WebViewTest):
+ (WebViewTest::webProcessCrashed):
+ * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h:
+
2015-03-06 Carlos Garcia Campos <[email protected]>
[GTK] Test /webkit2/WebKitWebView/sync-request-on-max-conns might fail after finished
Modified: releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp (182538 => 182539)
--- releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp 2015-04-08 15:54:49 UTC (rev 182538)
+++ releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp 2015-04-08 15:59:06 UTC (rev 182539)
@@ -231,6 +231,12 @@
g_assert(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(p2.get()));
assertObjectIsDeletedWhenTestFinishes(G_OBJECT(p2.get()));
+ // Manually handling a DOM object owned by the cache shouldn't crash when the cache has more than one reference.
+ GRefPtr<WebKitDOMElement> p3 = adoptGRef(webkit_dom_document_create_element(document, "P", nullptr));
+ g_assert(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(p3.get()));
+ assertObjectIsDeletedWhenTestFinishes(G_OBJECT(p3.get()));
+ webkit_dom_node_append_child(WEBKIT_DOM_NODE(div), WEBKIT_DOM_NODE(p3.get()), nullptr);
+
// DOM objects removed from the document are also correctly handled by the cache.
WebKitDOMElement* a = webkit_dom_document_create_element(document, "A", nullptr);
g_assert(WEBKIT_DOM_IS_ELEMENT(a));
Modified: releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp (182538 => 182539)
--- releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp 2015-04-08 15:54:49 UTC (rev 182538)
+++ releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp 2015-04-08 15:59:06 UTC (rev 182539)
@@ -86,9 +86,11 @@
test->loadHtml("<html></html>", 0);
test->waitUntilLoadFinished();
- g_signal_connect(test->m_webView, "web-process-crashed",
+ g_signal_connect_after(test->m_webView, "web-process-crashed",
G_CALLBACK(webProcessCrashedCallback), test);
+ test->m_expectedWebProcessCrash = true;
+
GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
"/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
@@ -100,6 +102,7 @@
-1, 0, 0));
g_assert(!result);
g_main_loop_run(test->m_mainLoop);
+ test->m_expectedWebProcessCrash = false;
}
static void testWebExtensionWindowObjectCleared(WebViewTest* test, gconstpointer)
Modified: releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp (182538 => 182539)
--- releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp 2015-04-08 15:54:49 UTC (rev 182538)
+++ releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp 2015-04-08 15:59:06 UTC (rev 182539)
@@ -34,8 +34,10 @@
, m_javascriptResult(0)
, m_resourceDataSize(0)
, m_surface(0)
+ , m_expectedWebProcessCrash(false)
{
assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView));
+ g_signal_connect(m_webView, "web-process-crashed", G_CALLBACK(WebViewTest::webProcessCrashed), this);
}
WebViewTest::~WebViewTest()
@@ -50,6 +52,16 @@
g_main_loop_unref(m_mainLoop);
}
+gboolean WebViewTest::webProcessCrashed(WebKitWebView*, WebViewTest* test)
+{
+ if (test->m_expectedWebProcessCrash) {
+ test->m_expectedWebProcessCrash = false;
+ return FALSE;
+ }
+ g_assert_not_reached();
+ return TRUE;
+}
+
void WebViewTest::loadURI(const char* uri)
{
m_activeURI = uri;
Modified: releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h (182538 => 182539)
--- releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h 2015-04-08 15:54:49 UTC (rev 182538)
+++ releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h 2015-04-08 15:59:06 UTC (rev 182539)
@@ -72,6 +72,8 @@
bool runWebProcessTest(const char* suiteName, const char* testName);
+ static gboolean webProcessCrashed(WebKitWebView*, WebViewTest*);
+
WebKitWebView* m_webView;
GMainLoop* m_mainLoop;
CString m_activeURI;
@@ -82,6 +84,7 @@
GUniquePtr<char> m_resourceData;
size_t m_resourceDataSize;
cairo_surface_t* m_surface;
+ bool m_expectedWebProcessCrash;
private:
void doMouseButtonEvent(GdkEventType, int, int, unsigned, unsigned);