<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="12" style="border: 1px #c9c399 solid; border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
    <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://git.reviewboard.kde.org/r/120110/">https://git.reviewboard.kde.org/r/120110/</a>
     </td>
    </tr>
   </table>
   <br />










<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On September 9th, 2014, 9:04 a.m. UTC, <b>David Edmundson</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  


<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
 <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
    <a href="https://git.reviewboard.kde.org/r/120110/diff/1/?file=310511#file310511line171" style="color: black; font-weight: bold; text-decoration: underline;">src/declarativeimports/core/datasource.cpp</a>
    <span style="font-weight: normal;">

     (Diff revision 1)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">void DataSource::modelChanged(const QString &sourceName, QAbstractItemModel *model)</pre></td>

  </tr>
 </tbody>



 
 

 <tbody>

  <tr>
    <th bgcolor="#f0f0f0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">166</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">    <span class="n">connect</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="o">&</span><span class="n">QObject</span><span class="o">::</span><span class="n">destroyed</span><span class="p">,</span> <span class="p">[</span> <span class="o">=</span> <span class="p">]()</span> <span class="p">{</span></pre></td>
    <th bgcolor="#f0f0f0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">171</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">    <span class="n">connect</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="o">&</span><span class="n">QObject</span><span class="o">::</span><span class="n">destroyed</span><span class="p">,</span> <span class="p">[</span> <span class="o">=</span> <span class="p">]()</span> <span class="p">{</span></pre></td>
  </tr>

 </tbody>

</table>

  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;"><p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">Nice work identifying the cause, but I think we can improve the fix.</p>
<p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">We were calling this lambda after the datasource object is deleted so this (and therefore m_models) is pointing to random memory, we just happen to be resetting the random memory to zero just beforehand, but it's not a fix that is going to work for long.</p>
<p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">It's interesting that there's a model that outlives the datasource, that implies a buggy datasource somewhere... but we need to fix this too.</p>
<p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">It could be solved by using a normal slot so we get automatic disconnect wheh the receiver is destroyed. </p>
<p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">Can probably be done with better lambdas but I don't know how.</p></pre>
 </blockquote>



 <p>On September 9th, 2014, 10:29 a.m. UTC, <b>Joseph Wenninger</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;"><p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">With a traditional slot the model has to have a property telling it's sourcename or we need a second inverse map. If I'm not mistaken, QQMLPropertyMap does not allow lookups or item removals by the value, but only by key. The first solution makes it more difficult for users of the API, the second solution isn't that nice either. What would be your idea to keep track of the sourcename for a model being deleted.</p></pre>
 </blockquote>







</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;"><p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">Just discussed in real life, came up with the correct patch where the lambda auto disconnects (thanks Aleix)</p></pre>
<br />




<p>- David</p>


<br />
<p>On September 9th, 2014, 10:38 a.m. UTC, Joseph Wenninger wrote:</p>









<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="12" style="border: 1px #888a85 solid; border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
 <tr>
  <td>

<div>Review request for KDE Frameworks and Plasma.</div>
<div>By Joseph Wenninger.</div>


<p style="color: grey;"><i>Updated Sept. 9, 2014, 10:38 a.m.</i></p>









<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt;">Repository: </b>
plasma-framework
</div>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
 <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;"><p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">Fix a crash when shutting down plasma shell, while destruction models</p>
<p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">While porting the kate session applet to plasma KF5, I noticed plasmashell crashing while using "kquitapp5 plasmashell" while destroying the model in the clipboard engine and in my engine (which is based on the clipboard engine). </p>
<p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">The problem for me was, that the lambda  in Plasma::DataEngine:167 accessed m_models, which was/is not valid anymore.</p>
<p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">Thread 1 (Thread 0x7f2f4cadb880 (LWP 4241)):<br style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: normal;" />
[KCrash Handler]</p>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">6  0x00007f2f488336df in QQmlOpenMetaObject::setValue(QByteArray const&, QVariant const&) () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Qml.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">7  0x00007f2f486c6d14 in QQmlPropertyMap::clear(QString const&) () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Qml.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">8  0x00007f2f2dfb94e4 in Plasma::DataSource::<lambda()>::operator()(void) const (__closure=0x7fffb8e86670) at /home/jowenn/KDE/kf5/src/frameworks/plasma-framework/src/declarativeimports/core/datasource.cpp:167</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">9  0x00007f2f2dfb9b88 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, Plasma::DataSource::modelChanged(const QString&, QAbstractItemModel<em style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: normal;">)::<lambda()> >::call(Plasma::DataSource::<lambda()>, void </em>*) (f=..., arg=0x7fffb8e86800) at /home/jowenn/KDE/qt5/qtbase/src/corelib/kernel/qobjectdefs_impl.h:502</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">10 0x00007f2f2dfb9b5e in QtPrivate::Functor<Plasma::DataSource::modelChanged(const QString&, QAbstractItemModel<em style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: normal;">)::<lambda()>, 0>::call<QtPrivate::List<>, void>(Plasma::DataSource::<lambda()> &, void </em>, void **) (f=..., arg=0x7fffb8e86800) at /home/jowenn/KDE/qt5/qtbase/src/corelib/kernel/qobjectdefs_impl.h:559</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">11 0x00007f2f2dfb9b13 in QtPrivate::QFunctorSlotObject<Plasma::DataSource::modelChanged(const QString&, QAbstractItemModel<em style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: normal;">)::<lambda()>, 0, QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase </em>, QObject <em style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: normal;">, void </em><em style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: normal;">, bool </em>) (which=1, this_=0x56aee80, r=0x5776340, a=0x7fffb8e86800, ret=0x0) at /home/jowenn/KDE/qt5/qtbase/src/corelib/kernel/qobject_impl.h:200</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">12 0x00007f2f459656be in QMetaObject::activate(QObject<em style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: normal;">, int, int, void</em>*) () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">13 0x00007f2f4596609f in QObject::destroyed(QObject*) () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">14 0x00007f2f4596d70b in QObject::~QObject() () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">15 0x00007f2f458ddd1d in QAbstractItemModel::~QAbstractItemModel() () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">16 0x00007f2e401af49e in KateSessionsModel::~KateSessionsModel (this=0x5776340, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/kde/applications/kate/addons/sessionapplet/engine/katesessionsmodel.cpp:59</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">17 0x00007f2e401af4ce in KateSessionsModel::~KateSessionsModel (this=0x5776340, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/kde/applications/kate/addons/sessionapplet/engine/katesessionsmodel.cpp:61</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">18 0x00007f2f4596460c in QObjectPrivate::deleteChildren() () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">19 0x00007f2f4596d493 in QObject::~QObject() () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">20 0x00007f2f4b644e47 in Plasma::DataContainer::~DataContainer (this=0x5775ef0, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/frameworks/plasma-framework/src/plasma/datacontainer.cpp:37</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">21 0x00007f2f4b644e76 in Plasma::DataContainer::~DataContainer (this=0x5775ef0, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/frameworks/plasma-framework/src/plasma/datacontainer.cpp:40</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">22 0x00007f2f4596460c in QObjectPrivate::deleteChildren() () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">23 0x00007f2f4596d493 in QObject::~QObject() () from /home/jowenn/KDE/qt5/qtbase/lib/libQt5Core.so.5</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">24 0x00007f2f4b648c21 in Plasma::DataEngine::~DataEngine (this=0x5774b50, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/frameworks/plasma-framework/src/plasma/dataengine.cpp:76</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">25 0x00007f2e401ae418 in KateSessionsEngine::~KateSessionsEngine (this=0x5774b50, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/kde/applications/kate/addons/sessionapplet/engine/katesessionsengine.cpp:36</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">26 0x00007f2e401ae448 in KateSessionsEngine::~KateSessionsEngine (this=0x5774b50, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/kde/applications/kate/addons/sessionapplet/engine/katesessionsengine.cpp:38</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">27 0x00007f2f4b65133d in Plasma::DataEngineManager::unloadEngine (this=0x7f2f4b8dc7c0 <Plasma::(anonymous namespace)::Q_QGS_privateDataEngineManagerSelf::innerFunction()::holder>, name=...) at /home/jowenn/KDE/kf5/src/frameworks/plasma-framework/src/plasma/private/dataenginemanager.cpp:159</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">28 0x00007f2f4b64cc6d in Plasma::DataEngineConsumer::~DataEngineConsumer (this=0x552c070, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/frameworks/plasma-framework/src/plasma/dataengineconsumer.cpp:85</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">29 0x00007f2f2dfa523a in Plasma::DataSource::~DataSource (this=0x552c060, __in_chrg=<optimized out>) at /home/jowenn/KDE/kf5/src/frameworks/plasma-framework/src/declarativeimports/core/datasource.h:43</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">30 0x00007f2f2dfac8b8 in QQmlPrivate::QQmlElement<Plasma::DataSource>::~QQmlElement (this=0x552c060, __in_chrg=<optimized out>) at /home/jowenn/KDE/qt5/qtdeclarative/src/qml/qml/qqmlprivate.h:106</h1>
<h1 style="font-size: 100%;text-rendering: inherit;padding: 0;white-space: normal;margin: 0;line-height: inherit;">31 0x00007f2f2dfac8e8 in QQmlPrivate::QQmlElement<Plasma::DataSource>::~QQmlElement (this=0x552c060, __in_chrg=<optimized out>) at /home/jowenn/KDE/qt5/qtdeclarative/src/qml/qml/qqmlprivate.h:106</h1></pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;"><p style="padding: 0;text-rendering: inherit;margin: 0;line-height: inherit;white-space: inherit;">This part of plasma shell does not cause a crash for me anymore.</p></pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>src/declarativeimports/core/datasource.h <span style="color: grey">(3a8b522919f04f8581e98271aff55ccc001062c8)</span></li>

 <li>src/declarativeimports/core/datasource.cpp <span style="color: grey">(2e7a2af4919f85bb385e95f2a29f9cdb5e7ecfda)</span></li>

</ul>

<p><a href="https://git.reviewboard.kde.org/r/120110/diff/" style="margin-left: 3em;">View Diff</a></p>






  </td>
 </tr>
</table>








  </div>
 </body>
</html>