<?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>37521</bug_id>
          
          <creation_ts>2010-04-13 14:07:30 -0700</creation_ts>
          <short_desc>[Qt] QtWebKit crash on shutdown</short_desc>
          <delta_ts>2010-04-19 17:49:10 -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>WebKit Qt</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>36832</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Qt</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Anders Bakken">agbakken</reporter>
          <assigned_to name="Anders Bakken">agbakken</assigned_to>
          <cc>hausmann</cc>
    
    <cc>kbalazs</cc>
    
    <cc>koshuin</cc>
    
    <cc>laszlo.gombos</cc>
    
    <cc>yael</cc>
    
    <cc>zherczeg</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>212076</commentid>
    <comment_count>0</comment_count>
      <attachid>53278</attachid>
    <who name="Anders Bakken">agbakken</who>
    <bug_when>2010-04-13 14:07:30 -0700</bug_when>
    <thetext>Created attachment 53278
patch that fixes the crash

I get the following crash on shutdown of a Qt webkit application:

==8808== Invalid read of size 8
==8808==    at 0x9AF2E90: QObject::thread() const (qobject.cpp:1409)
==8808==    by 0x72801BD: WTF::isMainThread() (ThreadingQt.cpp:220)
==8808==    by 0x66C7ED5: WebCore::JSDOMWindowBase::commonJSGlobalData() (JSDOMWindowBase.cpp:155)
==8808==    by 0x66AF816: WebCore::collect(void*) (GCController.cpp:46)
==8808==    by 0x66AFADF: WebCore::GCController::gcTimerFired(WebCore::Timer&lt;WebCore::GCController&gt;*) (GCController.cpp:69)
==8808==    by 0x66AFC33: WebCore::Timer&lt;WebCore::GCController&gt;::fired() (Timer.h:98)
==8808==    by 0x6CA0A53: WebCore::ThreadTimers::sharedTimerFiredInternal() (ThreadTimers.cpp:112)
==8808==    by 0x6CA0986: WebCore::ThreadTimers::sharedTimerFired() (ThreadTimers.cpp:90)
==8808==    by 0x6E73E36: WebCore::SharedTimerQt::~SharedTimerQt() (SharedTimerQt.cpp:68)
==8808==    by 0x9AF59D6: QObjectPrivate::deleteChildren() (qobject.cpp:1972)
==8808==    by 0x9AF8BFB: QObject::~QObject() (qobject.cpp:969)
==8808==    by 0x8E7DCB3: QApplication::~QApplication() (qapplication.cpp:1138)
==8808==  Address 0x8 is not stack&apos;d, malloc&apos;d or (recently) free&apos;d
==8808== 
==8808== 
==8808== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==8808==  Access not within mapped region at address 0x8
==8808==    at 0x9AF2E90: QObject::thread() const (qobject.cpp:1409)
==8808==    by 0x72801BD: WTF::isMainThread() (ThreadingQt.cpp:220)
==8808==    by 0x66C7ED5: WebCore::JSDOMWindowBase::commonJSGlobalData() (JSDOMWindowBase.cpp:155)
==8808==    by 0x66AF816: WebCore::collect(void*) (GCController.cpp:46)
==8808==    by 0x66AFADF: WebCore::GCController::gcTimerFired(WebCore::Timer&lt;WebCore::GCController&gt;*) (GCController.cpp:69)
==8808==    by 0x66AFC33: WebCore::Timer&lt;WebCore::GCController&gt;::fired() (Timer.h:98)
==8808==    by 0x6CA0A53: WebCore::ThreadTimers::sharedTimerFiredInternal() (ThreadTimers.cpp:112)
==8808==    by 0x6CA0986: WebCore::ThreadTimers::sharedTimerFired() (ThreadTimers.cpp:90)
==8808==    by 0x6E73E36: WebCore::SharedTimerQt::~SharedTimerQt() (SharedTimerQt.cpp:68)
==8808==    by 0x9AF59D6: QObjectPrivate::deleteChildren() (qobject.cpp:1972)
==8808==    by 0x9AF8BFB: QObject::~QObject() (qobject.cpp:969)
==8808==    by 0x8E7DCB3: QApplication::~QApplication() (qapplication.cpp:1138)

It reproduces pretty much every time but the example is rather involved and includes adding some code to WebKit that may or may not be important for reproducing the problem. Let me know if you want to see the example. 

It seems like the problem is that isMainThread is called after QCoreApplication is deleted. 

I&apos;ve attached a patch that fixes it but I am not 100% about the following:

Could this thread be called in one thread while QCoreApplication is being deleted in another? If so, one would have to do some more thread-synchronization for this to be safe.


Should it return true or false if QCoreApplication doesn&apos;t exist?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>212809</commentid>
    <comment_count>1</comment_count>
    <who name="Zoltan Herczeg">zherczeg</who>
    <bug_when>2010-04-15 05:04:15 -0700</bug_when>
    <thetext>Is it a valgrind output?

Am I see right that QApplication destructor fires the shared timer system of WebCore? I am wondering the possible side effects of such call. Perhaps it would be better to delete the SharedTimer just before the destructor of QApplication...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>212920</commentid>
    <comment_count>2</comment_count>
    <who name="Anders Bakken">agbakken</who>
    <bug_when>2010-04-15 10:34:12 -0700</bug_when>
    <thetext>(In reply to comment #1)
&gt; Is it a valgrind output?
&gt; 
&gt; Am I see right that QApplication destructor fires the shared timer system of
&gt; WebCore? I am wondering the possible side effects of such call. Perhaps it
&gt; would be better to delete the SharedTimer just before the destructor of
&gt; QApplication...

Hi Zoltan

It is valgrind. I can&apos;t get gdb to run against a debug version of WebKit. I have to admit I wouldn&apos;t know about your proposed fix. I just saw the error and found a simple way to fix it. Maybe someone who knows the details better could comment.

regards

Anders</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>213521</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Hausmann">hausmann</who>
    <bug_when>2010-04-16 17:24:40 -0700</bug_when>
    <thetext>This is technically a duplicate of 36832, but I admit I like Anders&apos; solution</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>213522</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Hausmann">hausmann</who>
    <bug_when>2010-04-16 17:24:59 -0700</bug_when>
    <thetext>I meant bug 36832</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>213596</commentid>
    <comment_count>5</comment_count>
    <who name="Zoltan Herczeg">zherczeg</who>
    <bug_when>2010-04-17 02:35:32 -0700</bug_when>
    <thetext>As far as I see this is an assertion fail, so only debug builds may crash. And the poblem is not there I think. Actually a half destroyed QApplication fires all timers, and a timer can do practically anything in WebKit, like it can also access/changes the members of this QApplication. This is unsafe. I feel this fix hides the issue, not solve it. Anyway it is just my opinion, nothing more.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>213695</commentid>
    <comment_count>6</comment_count>
    <who name="Balazs Kelemen">kbalazs</who>
    <bug_when>2010-04-17 17:09:09 -0700</bug_when>
    <thetext>(In reply to comment #1)
&gt; Is it a valgrind output?
&gt; 
&gt; Am I see right that QApplication destructor fires the shared timer system of
&gt; WebCore? I am wondering the possible side effects of such call. Perhaps it
&gt; would be better to delete the SharedTimer just before the destructor of
&gt; QApplication...

Yep, this is exactly what happens here.
I think we can achieve the behavior what you mentioned by
installing a self-destroying slot for QApplication::aboutToQuit() into the
SharedTimerQt instance (and make it independent from the QApplication).
I will try it! :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>214384</commentid>
    <comment_count>7</comment_count>
    <who name="Simon Hausmann">hausmann</who>
    <bug_when>2010-04-19 17:45:45 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 36832 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>214387</commentid>
    <comment_count>8</comment_count>
      <attachid>53278</attachid>
    <who name="Simon Hausmann">hausmann</who>
    <bug_when>2010-04-19 17:49:10 -0700</bug_when>
    <thetext>Comment on attachment 53278
patch that fixes the crash

r- as http://trac.webkit.org/changeset/57818 was landed</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>53278</attachid>
            <date>2010-04-13 14:07:30 -0700</date>
            <delta_ts>2010-04-19 17:49:10 -0700</delta_ts>
            <desc>patch that fixes the crash</desc>
            <filename>patch</filename>
            <type>text/plain</type>
            <size>1082</size>
            <attacher name="Anders Bakken">agbakken</attacher>
            
              <data encoding="base64">SW5kZXg6IEphdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBKYXZhU2NyaXB0
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDU3NTI5KQorKysgSmF2YVNjcmlwdENvcmUvQ2hhbmdl
TG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzEsMTIgQEAKKzIwMTAtMDQtMTMgIEFuZGVycyBC
YWtrZW4gIDxBbmRlcnMgQmFra2VuIDxhZ2Jha2tlbkBnbWFpbC5jb20+PgorCisgICAgICAgIFJl
dmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgIFNhbml0eS1jaGVjayBRQ29yZUFw
cGxpYXRpb246Omluc3RhbmNlKCkgaW4gV1RGOjppc01haW5UaHJlYWQoKS4KKworICAgICAgICAq
IHd0Zi9xdC9UaHJlYWRpbmdRdC5jcHA6CisgICAgICAgIChXVEY6OmlzTWFpblRocmVhZCk6CisK
IDIwMTAtMDQtMTIgIEpvY2VseW4gVHVyY290dGUgIDxqb2NlbHluLnR1cmNvdHRlQG5va2lhLmNv
bT4KIAogICAgICAgICBSZXZpZXdlZCBieSBub2JvZHksIGJ1aWxkIGZpeC4KSW5kZXg6IEphdmFT
Y3JpcHRDb3JlL3d0Zi9xdC9UaHJlYWRpbmdRdC5jcHAKPT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gSmF2YVNjcmlw
dENvcmUvd3RmL3F0L1RocmVhZGluZ1F0LmNwcAkocmV2aXNpb24gNTc1MjkpCisrKyBKYXZhU2Ny
aXB0Q29yZS93dGYvcXQvVGhyZWFkaW5nUXQuY3BwCSh3b3JraW5nIGNvcHkpCkBAIC0yMTcsNyAr
MjE3LDcgQEAgVGhyZWFkSWRlbnRpZmllciBjdXJyZW50VGhyZWFkKCkKIAogYm9vbCBpc01haW5U
aHJlYWQoKQogewotICAgIHJldHVybiBRVGhyZWFkOjpjdXJyZW50VGhyZWFkKCkgPT0gUUNvcmVB
cHBsaWNhdGlvbjo6aW5zdGFuY2UoKS0+dGhyZWFkKCk7CisgICAgcmV0dXJuICFRQ29yZUFwcGxp
Y2F0aW9uOjppbnN0YW5jZSgpIHx8IChRVGhyZWFkOjpjdXJyZW50VGhyZWFkKCkgPT0gUUNvcmVB
cHBsaWNhdGlvbjo6aW5zdGFuY2UoKS0+dGhyZWFkKCkpOwogfQogCiBNdXRleDo6TXV0ZXgoKQo=
</data>
<flag name="review"
          id="36955"
          type_id="1"
          status="-"
          setter="hausmann"
    />
    <flag name="commit-queue"
          id="36956"
          type_id="3"
          status="-"
          setter="hausmann"
    />
          </attachment>
      

    </bug>

</bugzilla>