Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54098

crash in QCoreApplication::postEvent() after a QScopedPointer<QActionGroup,QScopedPointerDeleteLater> goes out of scope

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.6.0
    • None
    • OS X 10.9 and Linux (it will be a couple of days before I can test this under Qt 5.6.1)

    Description

      I have code in a KF5 application that sets up "docks" (toolbars) in which each dock widget has a context menu that can be used to remove the widget, among other things.
      With Qt4/KDE4, this context menu had to be released using deleteLater() to avoid pending events being delivered to the deleted object. For safety I prefer to use the same approach under Qt5 but now using a QScopedPointer because the method where this is happening has multiple exit point (https://git.reviewboard.kde.org/r/128016/).

      Before using QScopedPointer the code worked fine, but now that I allocate the QMenu and QActionGroup objects as a QScopedPointer with QScopedPointerDeleteLater I get a systematic crash when the QActionGroup goes out of scope. This happens both on Linux and on OS X, but I get a useful backtrace only on OS X:

      * thread #1: tid = 0x250329, 0x00000001036182e0 QtCore`QCoreApplication::postEvent(receiver=0x000000010b71b820, event=0x00000001249b1dd0, priority=0) + 32 at qcoreapplication.cpp:1399, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
        * frame #0: 0x00000001036182e0 QtCore`QCoreApplication::postEvent(receiver=0x000000010b71b820, event=0x00000001249b1dd0, priority=0) + 32 at qcoreapplication.cpp:1399
          frame #1: 0x0000000100eabc0f libKDevPlatformSublime.10.dylib`Sublime::IdealDockWidget::contextMenuRequested(QPoint const&) [inlined] QScopedPointerObjectDeleteLater<QObject>::cleanup(pointer=0x000000010b71b820) + 4815 at qscopedpointer.h:82
          frame #2: 0x0000000100eabc03 libKDevPlatformSublime.10.dylib`Sublime::IdealDockWidget::contextMenuRequested(QPoint const&) [inlined] QScopedPointer<QActionGroup, QScopedPointerObjectDeleteLater<QObject> >::~QScopedPointer() at qscopedpointer.h:101
          frame #3: 0x0000000100eabc03 libKDevPlatformSublime.10.dylib`Sublime::IdealDockWidget::contextMenuRequested(QPoint const&) [inlined] QScopedPointer<QActionGroup, QScopedPointerObjectDeleteLater<QObject> >::~QScopedPointer() at qscopedpointer.h:99
          frame #4: 0x0000000100eabc03 libKDevPlatformSublime.10.dylib`Sublime::IdealDockWidget::contextMenuRequested(this=<unavailable>, point=0x00007fff5fbfd118) + 4803 at idealdockwidget.cpp:210
          frame #5: 0x000000010364ba66 QtCore`QMetaObject::activate(QObject*, int, int, void**) [inlined] QtPrivate::QSlotObjectBase::call(this=<unavailable>, r=<unavailable>, a=<unavailable>) + 2070 at qobject_impl.h:124
          frame #6: 0x000000010364ba4b QtCore`QMetaObject::activate(sender=0x000000010cb2e730, signalOffset=<unavailable>, local_signal_index=<unavailable>, argv=<unavailable>) + 2043 at qobject.cpp:3715
          frame #7: 0x00000001025074ca QtWidgets`QWidget::event(QEvent*) [inlined] QWidget::customContextMenuRequested(this=0x000000010cb2e730) + 36 at moc_qwidget.cpp:652
          frame #8: 0x00000001025074a6 QtWidgets`QWidget::event(this=0x000000010cb2e730, event=<unavailable>) + 4470 at qwidget.cpp:8921
          frame #9: 0x00000001025b2273 QtWidgets`QAbstractButton::event(this=0x000000010cb2e730, e=<unavailable>) + 179 at qabstractbutton.cpp:1088
          frame #10: 0x000000010267ffa3 QtWidgets`QToolButton::event(this=0x000000010cb2e730, event=0x00007fff5fbfd0f8) + 307 at qtoolbutton.cpp:970
          frame #11: 0x00000001024c6f66 QtWidgets`QApplicationPrivate::notify_helper(this=<unavailable>, receiver=0x000000010cb2e730, e=0x00007fff5fbfd0f8) + 294 at qapplication.cpp:3714
          frame #12: 0x00000001024c8f86 QtWidgets`QApplication::notify(this=<unavailable>, receiver=0x000000010cb2e730, e=0x00007fff5fbfd0f8) + 3110 at qapplication.cpp:3355
          frame #13: 0x0000000103617b07 QtCore`QCoreApplication::notifyInternal2(receiver=0x000000010cb2e730, event=0x00007fff5fbfd0f8) + 167 at qcoreapplication.cpp:1020
          frame #14: 0x00000001025282e3 QtWidgets`QWidgetWindow::handleMouseEvent(QMouseEvent*) [inlined] QCoreApplication::sendSpontaneousEvent(receiver=0x000000010cb2e730, event=0x0000000103196900) + 3619 at qcoreapplication.h:230
          frame #15: 0x00000001025282d1 QtWidgets`QWidgetWindow::handleMouseEvent(this=<unavailable>, event=0x00007fff5fbfd7a8) + 3601 at qwidgetwindow.cpp:561
      

      The exact location:

      frame #0: 0x00000001036182e0 QtCore`QCoreApplication::postEvent(receiver=0x0000000122f33920, event=0x000000011ab0fc30, priority=0) + 32 at qcoreapplication.cpp:1399
         1396     }
         1397 
         1398     QThreadData * volatile * pdata = &receiver->d_func()->threadData;
      -> 1399     QThreadData *data = *pdata;
         1400     if (!data) {
         1401         // posting during destruction? just delete the event to prevent a leak
         1402         delete event;
      

      Shouldn't the test on "posting during destruction" include a check if pdata!=NULL, possibly even if receiver->d_func() doesn't return NULL?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            rjvbertin René Bertin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes