[katepart crash] Critical bug in KProcIO/KProcess?

Dominik Haumann dhdev at gmx.de
Mon Apr 3 23:42:00 BST 2006


Hi,

katepart is notified for every external modified file. It then pops up a
dialog, where you can click "View Differences", which will open kompare
then. Then sometimes, katepart crashes.

How to reproduce:
1. open kwrite
2. open an empty file FILE
3. go into the konsole, and type echo "" >> FILE
4. activate kwrite again, and click "View Difference"

My backtrace is attached.

Related bug reports are:
http://bugs.kde.org/show_bug.cgi?id=123887 (same bt as my own)
http://bugs.kde.org/show_bug.cgi?id=107556 (maybe)
http://bugs.kde.org/show_bug.cgi?id=109644 (maybe)

Katepart uses the following code in kdelibs/kate/part/katedialogs.cpp:

  void KateModOnHdPrompt::slotDiff()
  {
    KProcIO *p = new KProcIO();
    p->setComm( KProcess::All );
    *p << "diff" << "-ub" << "-" <<  m_doc->url().path();
    connect( p, SIGNAL(processExited(KProcess*)), this, SLOT(slotPDone(KProcess*)) );
    connect( p, SIGNAL(readReady(KProcIO*)), this, SLOT(slotPRead(KProcIO*)) );

    setCursor( WaitCursor );

    p->start( KProcess::NotifyOnExit, true );

    uint lastln =  m_doc->numLines();
    for ( uint l = 0; l <  lastln; l++  )
      p->writeStdin(  m_doc->textLine( l ), l < lastln ); 

    p->closeWhenDone();
  }

Explanation of slotDiff():
We first want the output, so we use the signal readReady().
*After* this, we think processExited() is emitted. So m_tmpfile is not NULL
in slotPDone, because it is created before in slotPRead. This works in 90%
of the cases.

  void KateModOnHdPrompt::slotPRead( KProcIO *p)
  {
    // create a file for the diff if we haven't one allready
    if ( ! m_tmpfile )
      m_tmpfile = new KTempFile();
    // put all the data we have in it
    QString stmp;
    while ( p->readln( stmp, false ) > -1 )
      *m_tmpfile->textStream() << stmp << endl;

    p->ackRead();
  }

  void KateModOnHdPrompt::slotPDone( KProcess *p )
  {
    setCursor( ArrowCursor );
    m_tmpfile->close();
  
    if ( ! p->normalExit() /*|| p->exitStatus()*/ )
    {
      KMessageBox::sorry( this,
                          i18n("The diff command failed. Please make sure that "
                               "diff(1) is installed and in your PATH."),
                          i18n("Error Creating Diff") );
      return;
    }
 
    KRun::runURL( m_tmpfile->name(), "text/x-diff", true );
    delete m_tmpfile;
    m_tmpfile = 0;
  }

However, the backtrace shows, that slotPRead() is not called, but only slotPDone.
so m_tmpfile is NULL, and katepart crashes.

The problem seems to be, that KProcIO does not emit readReady() in time, if
the process finished almost immediately after it was started (that's why I
wrote in step #2 "en empty file", so that the diff is very short). Maybe
it does not emit readReady() at all in this case.

Question: How to fix this? This affects all apps using katepart (Kile, Quanta,
KDevelop, Kate/KWrite etc...) and all apps using KProcIO in this way.

I'm not sure, if my explanation is correct, but it would explain the backtrace.
The bug is 100% reproducable for me in KDE 3.5.

Greetings,
Dominik
-------------- next part --------------
Using host libthread_db library "/lib/libthread_db.so.1".
`system-supplied DSO at 0xffffe000' has disappeared; keeping its symbols.
[Thread debugging using libthread_db enabled]
[New Thread 16384 (LWP 6154)]
[New Thread 32769 (LWP 6158)]
[KCrash handler]
#7  0xb773f631 in KTempFile::close (this=0x0)
    at /home/dh/kde/3.5/kdelibs/kdecore/ktempfile.cpp:253
#8  0xb6364da1 in KateModOnHdPrompt::slotPDone (this=0xbfe3df70, p=0x83a6480)
    at /home/dh/kde/3.5/kdelibs/kate/part/katedialogs.cpp:1668
#9  0xb6353f73 in KateModOnHdPrompt::qt_invoke (this=0xbfe3df70, _id=89, 
    _o=0xbfe3d710) at katedialogs.moc:1218
#10 0xb701e744 in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#11 0xb76d6c95 in KProcess::processExited (this=0x83a6480, t0=0x83a6480)
    at kprocess.moc:137
#12 0xb76d5a49 in KProcess::processHasExited (this=0x83a6480, state=0)
    at /home/dh/kde/3.5/kdelibs/kdecore/kprocess.cpp:830
#13 0xb76d8552 in KProcessController::slotDoHousekeeping (this=0x81385d8)
    at /home/dh/kde/3.5/kdelibs/kdecore/kprocctrl.cpp:202
#14 0xb76d895d in KProcessController::qt_invoke (this=0x81385d8, _id=2, 
    _o=0xbfe3d8c0) at kprocctrl.moc:82
#15 0xb701e744 in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#16 0xb701ed6b in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#17 0xb737c500 in QSocketNotifier::activated ()
   from /usr/qt/3/lib/libqt-mt.so.3
#18 0xb703bac0 in QSocketNotifier::event () from /usr/qt/3/lib/libqt-mt.so.3
#19 0xb6fba6bf in QApplication::internalNotify ()
   from /usr/qt/3/lib/libqt-mt.so.3
#20 0xb6fba85c in QApplication::notify () from /usr/qt/3/lib/libqt-mt.so.3
#21 0xb768b56c in KApplication::notify (this=0xbfe3f320, receiver=0x8138640, 
    event=0xbfe3dc80) at /home/dh/kde/3.5/kdelibs/kdecore/kapplication.cpp:550
#22 0xb6fade63 in QEventLoop::activateSocketNotifiers ()
   from /usr/qt/3/lib/libqt-mt.so.3
#23 0xb6f6644c in QEventLoop::processEvents () from /usr/qt/3/lib/libqt-mt.so.3
#24 0xb6fd1231 in QEventLoop::enterLoop () from /usr/qt/3/lib/libqt-mt.so.3
#25 0xb6fb985f in QApplication::enter_loop () from /usr/qt/3/lib/libqt-mt.so.3
#26 0xb71b4dc2 in QDialog::exec () from /usr/qt/3/lib/libqt-mt.so.3
#27 0xb637d6ee in KateDocument::slotModifiedOnDisk (this=0x8245908)
    at /home/dh/kde/3.5/kdelibs/kate/part/katedocument.cpp:4266
#28 0xb636a115 in KateDocument::qt_invoke (this=0x8245908, _id=93, 
    _o=0xbfe3e200) at katedocument.moc:1156
#29 0xb701e6ca in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#30 0xb63a9b0e in KateView::gotFocus (this=0x821fe80, t0=0x821fe80)
    at kateview.moc:663
#31 0xb63e08df in KateViewInternal::focusInEvent (this=0x820fc20)
    at /home/dh/kde/3.5/kdelibs/kate/part/kateviewinternal.cpp:2928
#32 0xb705849d in QWidget::event () from /usr/qt/3/lib/libqt-mt.so.3
#33 0xb6fba6bf in QApplication::internalNotify ()
   from /usr/qt/3/lib/libqt-mt.so.3
#34 0xb6fba85c in QApplication::notify () from /usr/qt/3/lib/libqt-mt.so.3
#35 0xb768b56c in KApplication::notify (this=0xbfe3f320, receiver=0x820fc20, 
    event=0xbfe3e620) at /home/dh/kde/3.5/kdelibs/kdecore/kapplication.cpp:550
#36 0xb70578e7 in QWidget::setFocus () from /usr/qt/3/lib/libqt-mt.so.3
#37 0xb6f4954b in QApplication::closePopup () from /usr/qt/3/lib/libqt-mt.so.3
#38 0xb7055aa6 in QWidget::hide () from /usr/qt/3/lib/libqt-mt.so.3
#39 0xb712e8f4 in QPopupMenu::hide () from /usr/qt/3/lib/libqt-mt.so.3
#40 0xb7129bba in QPopupMenu::hideAllPopups () from /usr/qt/3/lib/libqt-mt.so.3
#41 0xb7129df1 in QPopupMenu::byeMenuBar () from /usr/qt/3/lib/libqt-mt.so.3
#42 0xb7131a60 in QPopupMenu::mousePressEvent ()
   from /usr/qt/3/lib/libqt-mt.so.3
#43 0xb79892d0 in KPopupMenu::mousePressEvent (this=0x8335660, e=0xbfe3ecd0)
    at /home/dh/kde/3.5/kdelibs/kdeui/kpopupmenu.cpp:502
#44 0xb70586b7 in QWidget::event () from /usr/qt/3/lib/libqt-mt.so.3
#45 0xb6fba6bf in QApplication::internalNotify ()
   from /usr/qt/3/lib/libqt-mt.so.3
#46 0xb6fbaa82 in QApplication::notify () from /usr/qt/3/lib/libqt-mt.so.3
#47 0xb768b56c in KApplication::notify (this=0xbfe3f320, receiver=0x8335660, 
    event=0xbfe3ecd0) at /home/dh/kde/3.5/kdelibs/kdecore/kapplication.cpp:550
#48 0xb6f53bec in QETWidget::translateMouseEvent ()
   from /usr/qt/3/lib/libqt-mt.so.3
#49 0xb6f522a8 in QApplication::x11ProcessEvent ()
   from /usr/qt/3/lib/libqt-mt.so.3
#50 0xb6f65ec5 in QEventLoop::processEvents () from /usr/qt/3/lib/libqt-mt.so.3
#51 0xb6fd1231 in QEventLoop::enterLoop () from /usr/qt/3/lib/libqt-mt.so.3
#52 0xb6fd1186 in QEventLoop::exec () from /usr/qt/3/lib/libqt-mt.so.3
#53 0xb6fb982f in QApplication::exec () from /usr/qt/3/lib/libqt-mt.so.3
#54 0xb66f252b in kdemain (argc=1, argv=0x8102480)
    at /home/dh/kde/3.5/kdebase/kate/app/kwritemain.cpp:692
#55 0xb66f8808 in kdeinitmain (argc=1, argv=0x8102480)
    at kdeinit_kwrite.la.cpp:3
#56 0x0804e6a0 in launch (argc=1, _name=0x8102f3c "kwrite", 
    args=0x8102f43 "\001", cwd=0x0, envc=1, envs=0x8102f54 "", 
    reset_env=false, tty=0x0, avoid_loops=false, 
    startup_id_str=0x8102f58 "arnor;1144098685;930745;6142_TIME1637385072")
    at /home/dh/kde/3.5/kdelibs/kinit/kinit.cpp:639
#57 0x0804f9b6 in handle_launcher_request (sock=8)
    at /home/dh/kde/3.5/kdelibs/kinit/kinit.cpp:1203
#58 0x080500ab in handle_requests (waitForPid=0)
    at /home/dh/kde/3.5/kdelibs/kinit/kinit.cpp:1406
#59 0x0805164f in main (argc=2, argv=0xbfe3fa34, envp=0xbfe3fa40)
    at /home/dh/kde/3.5/kdelibs/kinit/kinit.cpp:1850


More information about the kde-core-devel mailing list