[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Fix crash in KoMainWindow.cpp
From:       Johannes Simon <johannes.simon () gmail ! com>
Date:       2010-05-24 20:12:27
Message-ID: A7E994D8-0E48-4430-AFAB-224BC7436EFE () gmail ! com
[Download RAW message or body]

I'm a bit too lazy to open a review request for this, as it's a bit cumbersome to \
convert my git diff into a valid one for reviewboard, so here's my patch to fix a \
crash in KoMainWindow.cpp that happened upon closing KWord. Basically, a view that \
was the current active view was destroyed, which (after it was destroyed) triggered a \
slot in KoMainWindow.cpp that did some simple operations on the active view, which \
resulted in a crash.

Here is the fix, I'm putting it up for review:

diff --git a/libs/main/KoMainWindow.cpp b/libs/main/KoMainWindow.cpp
index 959ad2e..8559af9 100644
--- a/libs/main/KoMainWindow.cpp
+++ b/libs/main/KoMainWindow.cpp
@@ -482,7 +482,10 @@ void KoMainWindow::setRootDocument(KoDocument *doc)
     emit restoringDone();
 
     while(!oldRootViews.isEmpty()) {
-        delete oldRootViews.takeFirst();
+        KoView *oldRootView = oldRootViews.takeFirst();
+        if ( oldRootView == d->activeView )
+            d->activeView = 0;
+        delete oldRootView;
     }
     if (oldRootDoc && oldRootDoc->viewCount() == 0) {
         //kDebug(30003) <<"No more views, deleting old doc" << oldRootDoc;


All this looks highly suspicious to me, especially because d->activeView is still one \
of the oldRootViews when it should actually be something new. I attached the crash \
backtrace for your reference.

- Johannes


["backtrace.txt" (backtrace.txt)]

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000021bcd6a08
KXMLGUIClient::factory (this=0x21bcd6a00) at \
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_kde_kdelibs4/work/kdelibs-4.4.2/kdeui/xmlgui/kxmlguiclient.cpp:588
 588	  return d->m_factory;
(gdb) back
#0  KXMLGUIClient::factory (this=0x21bcd6a00) at \
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_kde_kdelibs4/work/kdelibs-4.4.2/kdeui/xmlgui/kxmlguiclient.cpp:588
 #1  0x00000001014e1616 in KXMLGUIFactory::removeClient (this=0x103eade70, \
client=0x21bcd6a00) at \
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_kde_kdelibs4/work/kdelibs-4.4.2/kdeui/xmlgui/kxmlguifactory.cpp:392
 #2  0x0000000100079dc8 in KoMainWindow::slotActivePartChanged (this=0x103e25100, \
newPart=0x0) at /Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoMainWindow.cpp:1566
 #3  0x00000001000790d9 in KoMainWindow::qt_metacall (this=0x103e25100, \
_c=QMetaObject::InvokeMetaMethod, _id=<value temporarily unavailable, due to \
optimizations>, _a=0x7fff5fbfd560) at KoMainWindow.moc:168 #4  0x000000010210eddb in \
QMetaObject::activate () #5  0x0000000100cf6021 in \
KParts::PartManager::activePartChanged (this=<value temporarily unavailable, due to \
optimizations>, _t1=0x0) at partmanager.moc:161 #6  0x0000000100cf6bcc in \
KParts::PartManager::setActivePart (this=0x103e7b100, part=0x0, widget=0x0) at \
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_kde_kdelibs4/work/kdelibs-4.4.2/kparts/partmanager.cpp:481
 #7  0x0000000100cf656e in KParts::PartManager::slotWidgetDestroyed \
(this=0x103e7b100) at \
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_kde_kdelibs4/work/kdelibs-4.4.2/kparts/partmanager.cpp:549
 #8  0x0000000100cf6771 in KParts::PartManager::qt_metacall (this=0x103e7b100, \
_c=QMetaObject::InvokeMetaMethod, _id=<value temporarily unavailable, due to \
optimizations>, _a=0x7fff5fbfd7c0) at partmanager.moc:103 #9  0x000000010210eddb in \
QMetaObject::activate () #10 0x000000010210f20e in QObject::destroyed ()
#11 0x000000010210f8a5 in QObject::~QObject ()
#12 0x0000000102635052 in QWidget::~QWidget ()
#13 0x000000010009a747 in KoView::~KoView (this=0x1199b68a0, __vtt_parm=0x1195d26a8) \
at /Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoView.cpp:187 #14 \
0x000000011951e3d8 in KWView::~KWView (this=0x1199b68a0) at \
/Users/joh/Applications/KDE4/src/koffice.git/kword/part/KWView.cpp:183 #15 \
0x000000010006c63b in KoMainWindow::setRootDocument (this=0x103e25100, \
doc=0x11ef9d6c0) at /Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoMainWindow.cpp:485
 #16 0x00000001000773e2 in KoMainWindow::slotLoadCompleted (this=0x103e25100) at \
/Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoMainWindow.cpp:706 #17 \
0x00000001000790e6 in KoMainWindow::qt_metacall (this=0x103e25100, \
_c=QMetaObject::InvokeMetaMethod, _id=<value temporarily unavailable, due to \
optimizations>, _a=0x7fff5fbfdc90) at KoMainWindow.moc:169 #18 0x000000010210eddb in \
QMetaObject::activate () #19 0x0000000100cee276 in KParts::ReadOnlyPart::openUrl \
(this=0x11ef9d6c0, url=<value temporarily unavailable, due to optimizations>) at \
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_kde_kdelibs4/work/kdelibs-4.4.2/kparts/part.cpp:560
 #20 0x0000000100045db3 in KoDocument::openUrl (this=0x11ef9d6c0, \
_url=@0x7fff5fbfe210) at \
/Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoDocument.cpp:1181 #21 \
0x000000010006dfe0 in KoMainWindow::openDocumentInternal (this=0x103e25100, \
url=@0x7fff5fbfe210, newdoc=0x11ef9d6c0) at \
/Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoMainWindow.cpp:671 #22 \
0x0000000100076241 in KoMainWindow::openDocument (this=0x103e25100, \
url=@0x7fff5fbfe210) at \
/Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoMainWindow.cpp:632 #23 \
0x000000010006ee22 in KoMainWindow::slotFileOpen (this=0x103e25100) at \
/Users/joh/Applications/KDE4/src/koffice.git/libs/main/KoMainWindow.cpp:1211 #24 \
0x0000000100078ee7 in KoMainWindow::qt_metacall (this=0x103e25100, \
_c=QMetaObject::InvokeMetaMethod, _id=<value temporarily unavailable, due to \
optimizations>, _a=0x7fff5fbfe470) at KoMainWindow.moc:140 #25 0x000000010210eddb in \
QMetaObject::activate () #26 0x00000001025d4151 in QAction::triggered ()
#27 0x00000001025d54f4 in QAction::activate ()
#28 0x00000001029236f9 in QAbstractButtonPrivate::click ()
#29 0x0000000102923991 in QAbstractButton::mouseReleaseEvent ()
#30 0x00000001029ebb52 in QToolButton::mouseReleaseEvent ()
#31 0x000000010262f2a1 in QWidget::event ()
#32 0x00000001029227d8 in QAbstractButton::event ()
#33 0x00000001029edbff in QToolButton::event ()
#34 0x00000001025da33d in QApplicationPrivate::notify_helper ()
#35 0x00000001025e0f20 in QApplication::notify ()
#36 0x00000001013d0320 in KApplication::notify (this=0x7fff5fbff670, \
receiver=0x11990c260, event=0x7fff5fbfed30) at \
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_kde_kdelibs4/work/kdelibs-4.4.2/kdeui/kernel/kapplication.cpp:302
 #37 0x0000000102108f8c in QCoreApplication::notifyInternal ()
#38 0x00000001025da4bc in qt_sendSpontaneousEvent ()
#39 0x0000000102593ab0 in qt_mac_handleMouseEvent ()
#40 0x0000000102586e56 in -[QCocoaView mouseUp:] ()
#41 0x00007fff84c2efa5 in -[NSWindow sendEvent:] ()
#42 0x000000010258d6ee in -[QCocoaWindow sendEvent:] ()
#43 0x00007fff84b64662 in -[NSApplication sendEvent:] ()
#44 0x00007fff84afb0aa in -[NSApplication run] ()
#45 0x0000000102599045 in QEventDispatcherMac::processEvents ()
#46 0x00000001021e0eb4 in QEventLoop::processEvents ()
#47 0x00000001021e11c4 in QEventLoop::exec ()
#48 0x00000001021e27ec in QCoreApplication::exec ()
#49 0x0000000100019f17 in kdemain (argc=<value temporarily unavailable, due to \
optimizations>, argv=<value temporarily unavailable, due to optimizations>) at \
/Users/joh/Applications/KDE4/src/koffice.git/kword/part/main.cpp:38 #50 \
0x000000010000aec4 in start ()



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic