<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>115058</bug_id>
          
          <creation_ts>2013-04-23 14:14:35 -0700</creation_ts>
          <short_desc>Assert in JSC::Heap::unprotect when closing facebook.com web site</short_desc>
          <delta_ts>2013-04-30 05:30:41 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore JavaScript</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows 7</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.facebook.com</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>110211</blocked>
          <everconfirmed>0</everconfirmed>
          <reporter name="Stephen">sfcheng</reporter>
          <assigned_to name="Allan Sandfeld Jensen">allan.jensen</assigned_to>
          <cc>allan.jensen</cc>
    
    <cc>commit-queue</cc>
    
    <cc>ggaren</cc>
    
    <cc>mhahnenberg</cc>
    
    <cc>sfcheng</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>880119</commentid>
    <comment_count>0</comment_count>
    <who name="Stephen">sfcheng</who>
    <bug_when>2013-04-23 14:14:35 -0700</bug_when>
    <thetext>I&apos;ve a browser application based on qt webkit 5.0.2. I use it to open facebook.com and do a little something such as reading some streaming news or post an update myself. After that, I close the QWebView which hosts the facebook.com website. More often than not, I got a debug assertion at the following location:

bool Heap::unprotect(JSValue k)
{
    ASSERT(k);
    ASSERT(m_globalData-&gt;apiLock().currentThreadIsHoldingLock());   &lt;-----Here is the debug assertion raised.

    if (!k.isCell())
        return false;

    return m_protectedValues.remove(k.asCell());
}

I can&apos;t reproduce the crash every time. If I open facebook.com and close it immediately, it usually doesn&apos;t crash. But after doing viewing and posting on it, it is very likely to crash. 
By the way, I&apos;ve already applied the patch I mentioned in another bug report: https://bugs.webkit.org/show_bug.cgi?id=113434 . That patch works well for most other websites. But facebook.com seems to be an exception. 

Here is a copy of the stack: 

I&apos;ve a browser application based on qt webkit 5.0.2. 

 	ntdll.dll!_ZwRaiseException@12()  + 0x12 bytes	
 	ntdll.dll!_ZwRaiseException@12()  + 0x12 bytes	
&gt;	Qt5WebKitd.dll!JSC::Heap::unprotect(JSC::JSValue k={...})  Line 344 + 0x42 bytes	C++
 	Qt5WebKitd.dll!JSC::gcUnprotect(JSC::JSCell * val=0x0ba1fe60)  Line 38	C++
 	Qt5WebKitd.dll!JSC::Bindings::RootObject::invalidate()  Line 132 + 0x10 bytes	C++
 	Qt5WebKitd.dll!WebCore::ScriptController::~ScriptController()  Line 86	C++
 	Qt5WebKitd.dll!WebCore::Frame::~Frame()  Line 228 + 0x5c bytes	C++
 	Qt5WebKitd.dll!WebCore::Frame::`scalar deleting destructor&apos;()  + 0xf bytes	C++
 	Qt5WebKitd.dll!WTF::RefCounted&lt;WebCore::StorageArea&gt;::deref()  Line 202 + 0x38 bytes	C++
 	Qt5WebKitd.dll!WTF::derefIfNotNull&lt;WebCore::FTPDirectoryDocumentParser&gt;(WebCore::FTPDirectoryDocumentParser * ptr=0x0e6d6968)  Line 54	C++
 	Qt5WebKitd.dll!WTF::RefPtr&lt;WebCore::StorageArea&gt;::~RefPtr&lt;WebCore::StorageArea&gt;()  Line 56 + 0x12 bytes	C++
 	Qt5WebKitd.dll!WebCore::Page::~Page()  Line 218 + 0xb5 bytes	C++
 	Qt5WebKitd.dll!WebCore::Page::`scalar deleting destructor&apos;()  + 0xf bytes	C++
 	Qt5WebKitd.dll!QWebPageAdapter::deletePage()  Line 237 + 0x1f bytes	C++
 	Qt5WebKitWidgetsd.dll!QWebPagePrivate::~QWebPagePrivate()  Line 238	C++
 	Qt5WebKitWidgetsd.dll!QWebPagePrivate::`scalar deleting destructor&apos;()  + 0xf bytes	C++
 	Qt5WebKitWidgetsd.dll!QWebPage::~QWebPage()  Line 1368 + 0x23 bytes	C++
 	MyApp.exe!WebPage::~WebPage()  Line 54 + 0x40 bytes	C++
 	MyApp.exe!WebPage::`scalar deleting destructor&apos;()  + 0xf bytes	C++
 	Qt5WebKitWidgetsd.dll!QWebViewPrivate::detachCurrentPage()  Line 236 + 0x24 bytes	C++
 	Qt5WebKitWidgetsd.dll!QWebViewPrivate::~QWebViewPrivate()  Line 64	C++
 	Qt5WebKitWidgetsd.dll!QWebViewPrivate::`scalar deleting destructor&apos;()  + 0xf bytes	C++
 	Qt5WebKitWidgetsd.dll!QWebView::~QWebView()  Line 199 + 0x23 bytes	C++
 	MyApp.exe!WebView::~WebView()  Line 180 + 0xef bytes	C++
 	MyApp.exe!WebView::`scalar deleting destructor&apos;()  + 0xf bytes	C++
 	Qt5Cored.dll!QObjectPrivate::deleteChildren()  Line 1764 + 0x24 bytes	C++
 	Qt5Widgetsd.dll!QWidget::~QWidget()  Line 1475	C++
 	Qt5Widgetsd.dll!QMdiSubWindow::~QMdiSubWindow()  Line 2289 + 0x8 bytes	C++
 	MyApp.exe!MdiSubWindow::~MdiSubWindow()  + 0x10 bytes	C++
 	MyApp.exe!MdiSubWindow::`scalar deleting destructor&apos;()  + 0xf bytes	C++
 	Qt5Cored.dll!qDeleteInEventHandler(QObject * o=0x0e6dba28)  Line 4093 + 0x21 bytes	C++
 	Qt5Cored.dll!QObject::event(QEvent * e=0x0e6c6888)  Line 1061 + 0xc bytes	C++
 	Qt5Widgetsd.dll!QWidget::event(QEvent * event=0x0e6c6888)  Line 8250 + 0x10 bytes	C++
 	Qt5Widgetsd.dll!QMdiSubWindow::event(QEvent * event=0x0e6c6888)  Line 2917	C++
 	Qt5Widgetsd.dll!QApplicationPrivate::notify_helper(QObject * receiver=0x0e6dba28, QEvent * e=0x0e6c6888)  Line 3398 + 0x11 bytes	C++
 	Qt5Widgetsd.dll!QApplication::notify(QObject * receiver=0x0e6dba28, QEvent * e=0x0e6c6888)  Line 3363 + 0x10 bytes	C++
 	Qt5Cored.dll!QCoreApplication::notifyInternal(QObject * receiver=0x0e6dba28, QEvent * event=0x0e6c6888)  Line 767 + 0x15 bytes	C++
 	Qt5Cored.dll!QCoreApplication::sendEvent(QObject * receiver=0x0e6dba28, QEvent * event=0x0e6c6888)  Line 203 + 0x39 bytes	C++
 	Qt5Cored.dll!QCoreApplicationPrivate::sendPostedEvents(QObject * receiver=0x00000000, int event_type=0, QThreadData * data=0x0b47db88)  Line 1368 + 0x12 bytes	C++
 	Qt5Cored.dll!QCoreApplication::sendPostedEvents(QObject * receiver=0x00000000, int event_type=0)  Line 1228 + 0x11 bytes	C++
 	Qt5Guid.dll!QWindowSystemInterface::sendWindowSystemEvents(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 515 + 0xa bytes	C++
 	qwindowsd.dll!QWindowsGuiEventDispatcher::sendPostedEvents()  Line 86 + 0xd bytes	C++
 	Qt5Cored.dll!qt_internal_proc(HWND__ * hwnd=0x00090cbc, unsigned int message=275, unsigned int wp=4294967294, long lp=0)  Line 423	C++
 	user32.dll!_InternalCallWinProc@20()  + 0x23 bytes	
 	user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes	
 	user32.dll!_DispatchMessageWorker@8()  + 0xed bytes	
 	user32.dll!_DispatchMessageW@4()  + 0xf bytes	
 	Qt5Cored.dll!QEventDispatcherWin32::processEvents(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 744	C++
 	qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 78 + 0xd bytes	C++
 	Qt5Cored.dll!QEventLoop::processEvents(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 137	C++
 	Qt5Cored.dll!QEventLoop::exec(QFlags&lt;enum QEventLoop::ProcessEventsFlag&gt; flags={...})  Line 212 + 0x26 bytes	C++
 	Qt5Cored.dll!QCoreApplication::exec()  Line 1020 + 0x15 bytes	C++
 	Qt5Guid.dll!QGuiApplication::exec()  Line 1184	C++
 	Qt5Widgetsd.dll!QApplication::exec()  Line 2674	C++
 	MyApp.exe!main(int argc=1, char * * argv=0x09a35bb0)  Line 94 + 0x6 bytes	C++
 	MyApp.exe!WinMain(HINSTANCE__ * instance=0x01080000, HINSTANCE__ * prevInstance=0x00000000, char * __formal=0x003c5742, int cmdShow=10)  Line 131 + 0x12 bytes	C++
 	MyApp.exe!__tmainCRTStartup()  Line 547 + 0x2c bytes	C
 	MyApp.exe!WinMainCRTStartup()  Line 371	C
 	kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes	
 	ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes	
 	ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>880722</commentid>
    <comment_count>1</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2013-04-24 11:19:54 -0700</bug_when>
    <thetext>The way to fix this is to put a JSLock inside ScriptController::~ScriptController.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>880741</commentid>
    <comment_count>2</comment_count>
    <who name="Stephen">sfcheng</who>
    <bug_when>2013-04-24 12:22:50 -0700</bug_when>
    <thetext>Do you have a patch to share for it?

By the way, I&apos;ve found this similar bug report https://bugs.webkit.org/show_bug.cgi?id=89809 . Among the changeset 121098, the modificiation done to Heap.cpp inside Heap::protect and Heap::unprotect is particullarly interesting ( check http://trac.webkit.org/changeset/121098/trunk/Source/JavaScriptCore/heap/Heap.cpp ). 

The one condition assert was modified into a two condition assert in this patch as shown below:

ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData-&gt;isSharedInstance());

Somehow, the 2nd conditon is removed again in the trunk version. If I add back the 2nd condition, it does stop the crash. This is just for your information. I don&apos;t really know what I am doing at all. 


(In reply to comment #1)
&gt; The way to fix this is to put a JSLock inside ScriptController::~ScriptController.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>881876</commentid>
    <comment_count>3</comment_count>
      <attachid>199829</attachid>
    <who name="Allan Sandfeld Jensen">allan.jensen</who>
    <bug_when>2013-04-26 07:08:41 -0700</bug_when>
    <thetext>Created attachment 199829
Patch

Patched as ggaren suggested</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>881918</commentid>
    <comment_count>4</comment_count>
      <attachid>199829</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2013-04-26 09:07:17 -0700</bug_when>
    <thetext>Comment on attachment 199829
Patch

Clearing flags on attachment: 199829

Committed r149188: &lt;http://trac.webkit.org/changeset/149188&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>881919</commentid>
    <comment_count>5</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2013-04-26 09:07:20 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>882749</commentid>
    <comment_count>6</comment_count>
    <who name="Stephen">sfcheng</who>
    <bug_when>2013-04-29 13:52:57 -0700</bug_when>
    <thetext>Thanks for the patch. Unfortunately, I am not able to directly apply this patch on qtwebkit 5.0.2. JSDOMWindowBase::commonVM() is not defined in qtwebkit 5.0.2.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>883024</commentid>
    <comment_count>7</comment_count>
    <who name="Allan Sandfeld Jensen">allan.jensen</who>
    <bug_when>2013-04-30 05:30:41 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; Thanks for the patch. Unfortunately, I am not able to directly apply this patch on qtwebkit 5.0.2. JSDOMWindowBase::commonVM() is not defined in qtwebkit 5.0.2.

It is called JSDOMWindowBase::commonJSGlobalData() in the Qt 5.0/5.1 branch. See https://codereview.qt-project.org/#change,55088</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>199829</attachid>
            <date>2013-04-26 07:08:41 -0700</date>
            <delta_ts>2013-04-26 09:07:17 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-115058-20130426160800.patch</filename>
            <type>text/plain</type>
            <size>1437</size>
            <attacher name="Allan Sandfeld Jensen">allan.jensen</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTQ5MTgxCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggMzdlNTNhZGIwZmRkMmQ5
NDU3Y2IyMTdjZmMzYzM0NjFiYWI3NDlhMS4uNmNhNGY2YjI3YTI0MWIwMDhlMDNmMTcxNTdiN2I1
YzEyMTJiYTNiNyAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE1IEBACisyMDEzLTA0LTI2ICBBbGxh
biBTYW5kZmVsZCBKZW5zZW4gIDxhbGxhbi5qZW5zZW5AZGlnaWEuY29tPgorCisgICAgICAgIEFz
c2VydCBpbiBKU0M6OkhlYXA6OnVucHJvdGVjdCB3aGVuIGNsb3NpbmcgZmFjZWJvb2suY29tIHdl
YiBzaXRlCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0x
MTUwNTgKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBH
cmFiIGEgSlNMb2NrIGJlZm9yZSBjYWxsaW5nIFJvb3RPYmplY3Q6OmludmFsaWRhdGUoKS4KKw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