Title: [182543] releases/WebKitGTK/webkit-2.4
Revision
182543
Author
[email protected]
Date
2015-04-08 09:31:01 -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.4/Source/WebCore/ChangeLog (182542 => 182543)


--- releases/WebKitGTK/webkit-2.4/Source/WebCore/ChangeLog	2015-04-08 16:25:54 UTC (rev 182542)
+++ releases/WebKitGTK/webkit-2.4/Source/WebCore/ChangeLog	2015-04-08 16:31:01 UTC (rev 182543)
@@ -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.4/Source/WebCore/bindings/gobject/DOMObjectCache.cpp (182542 => 182543)


--- releases/WebKitGTK/webkit-2.4/Source/WebCore/bindings/gobject/DOMObjectCache.cpp	2015-04-08 16:25:54 UTC (rev 182542)
+++ releases/WebKitGTK/webkit-2.4/Source/WebCore/bindings/gobject/DOMObjectCache.cpp	2015-04-08 16:31:01 UTC (rev 182543)
@@ -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.4/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdocument.c (182542 => 182543)


--- releases/WebKitGTK/webkit-2.4/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdocument.c	2015-04-08 16:25:54 UTC (rev 182542)
+++ releases/WebKitGTK/webkit-2.4/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdocument.c	2015-04-08 16:31:01 UTC (rev 182543)
@@ -309,6 +309,23 @@
     count = 0;
 
     document = webkit_web_view_get_dom_document(view);
+    body = webkit_dom_document_get_body(document);
+    WebKitDOMElement* p = webkit_dom_document_create_element(document, "P", NULL);
+    webkit_dom_node_append_child(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(p), NULL);
+    g_object_weak_ref(G_OBJECT(p), (GWeakNotify)weak_notify, &count);
+    /* This is wrong, p is transfer none and owned by the cache, but we shouldn't crash in that case. */
+    g_object_unref(p);
+
+    webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_IFRAME, NULL, NULL, NULL);
+
+    while (g_main_context_pending(NULL))
+        g_main_context_iteration(NULL, FALSE);
+
+    g_assert_cmpuint(count, ==, 1);
+
+    count = 0;
+
+    document = webkit_web_view_get_dom_document(view);
     WebKitDOMElement* div = webkit_dom_document_get_element_by_id(document, "test");
     g_assert(div);
     g_object_weak_ref(G_OBJECT(div), (GWeakNotify)weak_notify, &count);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to