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

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>291201</bug_id>
          
          <creation_ts>2012-01-10 19:29:21 +0000</creation_ts>
          <short_desc>ktp-contactlist crashes when setting status to &quot;Offline&quot;</short_desc>
          <delta_ts>2012-07-06 12:47:23 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>10</classification_id>
          <classification>Unmaintained</classification>
          <product>telepathy</product>
          <component>contactlist</component>
          <version>git-latest</version>
          <rep_platform>unspecified</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>crash</bug_severity>
          <target_milestone>0.4.0</target_milestone>
          
          <blocked>285413</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Elias Probst">mail</reporter>
          <assigned_to name="Telepathy Bugs">kde-telepathy-bugs-null</assigned_to>
          <cc>kde</cc>
    
    <cc>lacsilva</cc>
    
    <cc>mklapetek</cc>
          
          <cf_commitlink></cf_commitlink>
          <cf_versionfixedin></cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1212656</commentid>
    <comment_count>0</comment_count>
    <who name="Elias Probst">mail</who>
    <bug_when>2012-01-10 19:29:21 +0000</bug_when>
    <thetext>Application: ktp-contactlist (0.2.60)
KDE Platform Version: 4.7.97 (4.8 RC2 (4.7.97) (Compiled from sources)
Qt Version: 4.7.4
Operating System: Linux 3.1.6-gentoo x86_64
Distribution: &quot;Gentoo Base System release 2.0.3&quot;

-- Information about the crash:
- What I was doing when the application crashed:
→ Open Contact List
→ Set status of already existing accounts to &quot;Online&quot;
→ Open Accounts KCM
→ Add Account
→ Jabber/XMPP
→ Jabber ID: eliasp@amessage.de / Password: something random...
→ Notification appears: &quot;There was a problem while trying to connect eliasp@amessage.de - The SSL/TLS certificate received from server is expired&quot;
→ Set status in Contact List to &quot;Offline&quot;
→ ktp-contactlist crashes

The crash can be reproduced every time.

-- Backtrace:
Application: KDE Telepathy Contact List (ktp-contactlist), signal: Segmentation fault
[KCrash Handler]
#6  size (this=0x1ea00000041) at ../../include/QtCore/../../src/corelib/tools/qvector.h:124
#7  QSortFilterProxyModelPrivate::proxy_to_source (this=0x8279b0, proxy_index=...) at itemviews/qsortfilterproxymodel.cpp:369
#8  0x00007f8c2b092fc7 in QSortFilterProxyModel::mapToSource (this=&lt;optimized out&gt;, proxyIndex=&lt;optimized out&gt;) at itemviews/qsortfilterproxymodel.cpp:2500
#9  0x00007f8c2b091cb1 in QSortFilterProxyModel::data (this=&lt;optimized out&gt;, index=..., role=32) at itemviews/qsortfilterproxymodel.cpp:1713
#10 0x000000000043c5ac in data (arole=32, this=0x8ecab8) at /usr/include/qt4/QtCore/qabstractitemmodel.h:398
#11 ToolTipManager::showToolTip (this=0x917e90, menuItem=...) at /var/tmp/portage/net-im/telepathy-contact-list-9999/work/telepathy-kde-contact-list-9999/tooltips/tooltipmanager.cpp:153
#12 0x000000000043c888 in ToolTipManager::qt_metacall (this=0x917e90, _c=QMetaObject::InvokeMetaMethod, _id=&lt;optimized out&gt;, _a=0x7fffbf5899f0) at /var/tmp/portage/net-im/telepathy-contact-list-9999/work/telepathy-contact-list-9999_build/tooltipmanager.moc:77
#13 0x00007f8c2be8c3e0 in QMetaObject::activate (sender=0x917fd0, m=&lt;optimized out&gt;, local_signal_index=&lt;optimized out&gt;, argv=0x0) at kernel/qobject.cpp:3278
#14 0x00007f8c2be8bc17 in QObject::event (this=0x917fd0, e=&lt;optimized out&gt;) at kernel/qobject.cpp:1181
#15 0x00007f8c2ab801f8 in QApplicationPrivate::notify_helper (this=0x6936b0, receiver=0x917fd0, e=0x7fffbf58a130) at kernel/qapplication.cpp:4481
#16 0x00007f8c2ab848b0 in QApplication::notify (this=&lt;optimized out&gt;, receiver=0x917fd0, e=0x7fffbf58a130) at kernel/qapplication.cpp:4360
#17 0x00007f8c2caf0600 in KApplication::notify (this=0x7fffbf58a470, receiver=0x917fd0, event=0x7fffbf58a130) at /var/tmp/portage/kde-base/kdelibs-4.7.97-r1/work/kdelibs-4.7.97/kdeui/kernel/kapplication.cpp:311
#18 0x00007f8c2be79ce0 in QCoreApplication::notifyInternal (this=0x7fffbf58a470, receiver=0x917fd0, event=0x7fffbf58a130) at kernel/qcoreapplication.cpp:787
#19 0x00007f8c2bea3269 in sendEvent (event=0x7fffbf58a130, receiver=&lt;optimized out&gt;) at kernel/qcoreapplication.h:215
#20 QTimerInfoList::activateTimers (this=0x68bda0) at kernel/qeventdispatcher_unix.cpp:603
#21 0x00007f8c2bea0566 in timerSourceDispatch (source=&lt;optimized out&gt;) at kernel/qeventdispatcher_glib.cpp:184
#22 idleTimerSourceDispatch (source=&lt;optimized out&gt;) at kernel/qeventdispatcher_glib.cpp:231
#23 0x00007f8c26d6e0a2 in g_main_dispatch (context=0x68ace0) at gmain.c:2441
#24 g_main_context_dispatch (context=0x68ace0) at gmain.c:3011
#25 0x00007f8c26d6e7e8 in g_main_context_iterate (context=0x68ace0, block=1, dispatch=1, self=&lt;optimized out&gt;) at gmain.c:3089
#26 0x00007f8c26d6e9a4 in g_main_context_iteration (context=0x68ace0, may_block=1) at gmain.c:3152
#27 0x00007f8c2bea0b3c in QEventDispatcherGlib::processEvents (this=0x659dc0, flags=&lt;optimized out&gt;) at kernel/qeventdispatcher_glib.cpp:422
#28 0x00007f8c2ac174c6 in QGuiEventDispatcherGlib::processEvents (this=&lt;optimized out&gt;, flags=&lt;optimized out&gt;) at kernel/qguieventdispatcher_glib.cpp:204
#29 0x00007f8c2be79268 in QEventLoop::processEvents (this=&lt;optimized out&gt;, flags=...) at kernel/qeventloop.cpp:149
#30 0x00007f8c2be7945f in QEventLoop::exec (this=0x7fffbf58a3c0, flags=...) at kernel/qeventloop.cpp:201
#31 0x00007f8c2be7cb59 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:1064
#32 0x000000000042e65d in main (argc=1, argv=0x7fffbf58a748) at /var/tmp/portage/net-im/telepathy-contact-list-9999/work/telepathy-kde-contact-list-9999/main.cpp:62

Possible duplicates by query: bug 259161.

Reported using DrKonqi</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1212982</commentid>
    <comment_count>1</comment_count>
    <who name="Martin Klapetek">mklapetek</who>
    <bug_when>2012-01-11 10:30:48 +0000</bug_when>
    <thetext>This one is a bit tricky, it&apos;s a race condition. Basically what happens is that when you click &quot;Offline&quot; and the combobox closes, your mouse stays right above some contact and a tooltip is spawned. But before it can be fully drawn etc., the backend model data are already gone and therefore it hits null pointer and crashes.

I have basic safety checks in place, but it will have to be more sophisticated as that does not prevent the crash.

We could perhaps listen to some signal &quot;going offline&quot; (from global presence) and don&apos;t create tooltips when it receive that signal.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1214865</commentid>
    <comment_count>2</comment_count>
    <who name="Martin Klapetek">mklapetek</who>
    <bug_when>2012-01-15 22:54:37 +0000</bug_when>
    <thetext>*** Bug 291399 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1214866</commentid>
    <comment_count>3</comment_count>
    <who name="Martin Klapetek">mklapetek</who>
    <bug_when>2012-01-15 22:56:18 +0000</bug_when>
    <thetext>We need to solve this before 0.3 release as it is very annoying and very easy
to trigger.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1214875</commentid>
    <comment_count>4</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2012-01-15 23:59:28 +0000</bug_when>
    <thetext>But this crash is inside Qt itself, which implies 
 - either it&apos;s a Qt bug
 - our models are in a corrupt state for a small period of time.
 
QSortFilterProxyModelPrivate::proxy_to_source checks the index is valid. 

It must thinks it is.. otherwise it wouldn&apos;t continue and get to the line that crashes presumably &quot;m_sourceRows-&gt;size()&quot; in QSortFilterProxyModelPrivate::proxy_to_source

Our models should never be in a corrupt state, especially as all our stuff runs in one thread.

I made a version once that linked against Qt model test lib, we might want to try linking against that again and then triggering this issue. It might tell us where it&apos;s screwed. Failing that someone should re-read through accounts-model and look for potential discrepancies where an index could look valid even when it&apos;s not.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1214876</commentid>
    <comment_count>5</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2012-01-16 00:02:35 +0000</bug_when>
    <thetext>Eliasp (and other people who have seen this crash) were you in groups view or accounts view?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1214915</commentid>
    <comment_count>6</comment_count>
    <who name="Elias Probst">mail</who>
    <bug_when>2012-01-16 05:56:58 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; Eliasp (and other people who have seen this crash) were you in groups view or
&gt; accounts view?

You mean whether I was using the compact or the full list view? I&apos;m using &apos;compact&apos;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1214949</commentid>
    <comment_count>7</comment_count>
    <who name="Luis Silva">lacsilva</who>
    <bug_when>2012-01-16 08:38:10 +0000</bug_when>
    <thetext>It used to happen in account view. Curiously enough, after the latest qt upgrade (yesterday) I don&apos;t seem to be able to trigger this crash anymore. I am using Kubuntu packages for qt but compiling telepathy-qt from source (master).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1215002</commentid>
    <comment_count>8</comment_count>
    <who name="Martin Klapetek">mklapetek</who>
    <bug_when>2012-01-16 10:34:51 +0000</bug_when>
    <thetext>Few notes:
 - I tested it only with groups
 - Listening to the model&apos;s rowsRemoved() shows that the model emits the signal way before the data is actually removed (which might actually be correct), but there&apos;s a notable delay, therefore the model might still have &quot;valid&quot; indexes (but that&apos;s just a wild guess after severe sleep deprivation and sounds really wrong as the indexes imho should be invalidated by the remove-rows call)
 - I tested with recent Qt git snapshot, 100% reproducible
 - Checking for indexes in the tooltip part does not help, it returns true for isValid() everytime

Checking for the indexes</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1215004</commentid>
    <comment_count>9</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2012-01-16 10:42:34 +0000</bug_when>
    <thetext>That wouldn&apos;t cause a crash though, you&apos;d get it if you emitted rowsRemoved and there was a delay before removing from parent-&gt;mPriv-&gt;children.. and there isn&apos;t.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1216240</commentid>
    <comment_count>10</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2012-01-19 01:30:48 +0000</bug_when>
    <thetext>Right. We both made this supercomplicated when it turned out to be really really easy when we look in the right place.

QModelIndex.isValid() simply checks model exists and that rows + columns are non negative, it&apos;s not a continual check that works forever. It possibly checks &lt; rowCount on creation, but it&apos;s not checked each time you called isValid();

We had code in the tooltip-manager that:
1) saved a qmodelindex
2) waited a bit
3) used that modelindex

You should /never ever ever/ store a QModelIndex.

Patch
-    QModelIndex        item;
+    QPersistentModelIndex        item;

isValid now updates correctly so we don&apos;t crash.
Seems to fix it. If you test it, tomorrow I&apos;ll ship it if you&apos;re happy enough.

Alternate fix is to re-request the model index in prepareToolTip.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1216302</commentid>
    <comment_count>11</comment_count>
    <who name="Martin Klapetek">mklapetek</who>
    <bug_when>2012-01-19 08:47:17 +0000</bug_when>
    <thetext>While testing this I&apos;m reliably unable to reproduce it anymore (I was able to do that 100%).

&apos;Ship it&apos; from me!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1216384</commentid>
    <comment_count>12</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2012-01-19 12:40:25 +0000</bug_when>
    <thetext>Git commit b007f34980c2767d2a22e961ef6bb5dda237498f by David Edmundson.
Committed on 19/01/2012 at 13:39.
Pushed by davidedmundson into branch &apos;master&apos;.

Tooltip manager should store QPersistentModelIndexes not QModelIndexes

fixes a crash

M  +1    -1    tooltips/tooltipmanager.cpp

http://commits.kde.org/telepathy-contact-list/b007f34980c2767d2a22e961ef6bb5dda237498f</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>