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

QMacToolBar crash on exit (double memory release?)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.6.1
    • 5.5.0, 5.5.1
    • Extras: Mac
    • None
    • Mac OS X 10.10.5, MacBook Pro (Retina, Mid 2012)
    • 268f722c564eac77233074670fba742b51961415

    Description

      I'm porting an application from Qt 4 to Qt 5, and started using QMacToolBar in the process. The application has two different modes, with different sets of available toolbar buttons. This all works beautifully...until it segfaults while quitting the program. The error I get:

      Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
      0   libobjc.A.dylib               	0x00007fff9ae770dd objc_msgSend + 29
      1   org.qt-project.QtMacExtras    	0x000000010197cc0e QMacToolBarPrivate::~QMacToolBarPrivate() + 14
      2   org.qt-project.QtCore         	0x000000010216bb27 QObject::~QObject() + 1879
      3   org.qt-project.QtMacExtras    	0x000000010197c125 QMacToolBar::~QMacToolBar() + 53
      4   org.qt-project.QtCore         	0x000000010216bd95 QObjectPrivate::deleteChildren() + 245
      5   org.qt-project.QtWidgets      	0x00000001025c28ab QWidget::~QWidget() + 1467
      6   com.yourcompany.toolbarbug    	0x0000000101971ca6 main + 70
      7   com.yourcompany.toolbarbug    	0x00000001019713e4 start + 52
      

      I've managed to reproduce this with a minimal test case, which is attached. Looking at the code, the problem seems to be that in qmactoolbar.mm the QMacToolBar destructor contains:

      Q_D(QMacToolBar);
      [d->toolbar release];
      

      And the QMacToolBarPrivate destructor contains:

      [[toolbar delegate]release];
      [toolbar release];
      

      This looks like the memory for toolbar (the underlying NSToolbar) is released twice...and sure enough, if I comment out those lines from the QMacToolBar destructor, both the test case and my real application now exit gracefully.

      I'm not sure why this segfault isn't encountered consistently; the mactoolbar example usually works fine, although in tracking down the bug I'm pretty sure I got my application to crash a few times even with just one QMacToolBar instantiated. I'm guessing there's some sort of randomness in the application shutdown, where sometimes the second release attempt doesn't do enough damage to trigger a crash.

      Anyway, the fix seems pretty trivial if I'm understanding it correctly, so hopefully this can make it into a release soon.

      Attachments

        For Gerrit Dashboard: QTBUG-51309
        # Subject Branch Project Status CR V

        Activity

          People

            shausman Simon Hausmann
            jmbowman Jeremy Bowman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes