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

Regression: Memory leak / potential crash in QAction on Mac OS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • None
    • 5.3.0, 5.4.1
    • QPA
    • MacBook Pro; Mavericks 10.9.3; Qt5.3.0
    • macOS

    Description

      I am having some crash-on-exit problems on Qt5.3.0/Mavericks that I believe I have tracked down to a new memory leak in QAction.

      The attached test program demonstrates the leak. In that program, a QAction is added to a QMenu and then both are deallocated. When running the program on Qt5.3.0, leak detection (either using command-line "leaks" or using Instruments.app) shows that a QCocoaMenuItem is leaked. Some cocoa objects are also leaked, including an NSString containing the action's text.

      I believe this leak is leading to my crash-on-exit because some events are then emitted by the leaked QCocoaMenuItem after the enclosing QAction is gone. Explicitly leaking the entire QAction fixes the crash, and that's the only reliable workaround that I've found.

      I haven't yet been able to create a simple test case that re-creates the crash. This test case only shows the leak. Here's how I run it:

      cd qactiontest
      ~/Qt5.3.0/5.3/clang_64/bin/qmake qactiontest.pro
      make
      open qactiontest.app
      leaks qactiontest
      

      This occurs on 5.3.0 and the latest (2014-06-05) 5.3.1 snapshot. It was not a problem in the 5.3.0 beta or 5.2.1.

      Here's the output of leaks, showing all the leaked items:

      Process:         qactiontest [3596]
      Load Address:    0x100000000
      Version:         ???
      Code Type:       X86-64
      Parent Process:  launchd [297]
      
      Date/Time:       2014-06-05 14:22:41.458 -0700
      OS Version:      Mac OS X 10.9.3 (13D65)
      Report Version:  7
      
      leaks Report Version:  2.0
      Process 3596: 23293 nodes malloced for 3589 KB
      Process 3596: 14 leaks for 944 total leaked bytes.
      Leak: 0x6080000a4920  size=96  zone: DefaultMallocZone_0x1011d6000   __NSCFData  ObjC  CoreFoundation
      	0x7a13a570 0x00007fff 0x00001484 0x00000001 	p..z............
      	0x00000015 0x00000000 0x00000015 0x00000000 	................
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      	0x2d63614d 0x43453343 0x32444337 0x32393232 	Mac-C3EC7CD22292
      	0x46313839 0x00000000 0x00000000 0x00000000 	981F............
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      Leak: 0x610000000a10  size=16  zone: DefaultMallocZone_0x1011d6000
      	0x00000000 0x00000000 0x00000027 0x00000000 	........'.......
      Leak: 0x610000022320  size=32  zone: DefaultMallocZone_0x1011d6000
      	0x00000001 0x00000002 0x00000000 0x00000001 	................
      	0x00045d00 0x00006100 0x00000000 0x00000000 	.]...a..........
      Leak: 0x610000022560  size=32  zone: DefaultMallocZone_0x1011d6000
      	0x00000001 0x00000002 0x00000000 0x00000001 	................
      	0x00000a10 0x00006100 0x00000000 0x00000000 	.....a..........
      Leak: 0x6100000228a0  size=32  zone: DefaultMallocZone_0x1011d6000
      	0x000e3780 0x00006100 0x00000100 0x00000000 	.7...a..........
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      Leak: 0x610000022de0  size=32  zone: DefaultMallocZone_0x1011d6000   __NSCFString  ObjC  CoreFoundation  "LeakedString!"
      Leak: 0x610000045ca0  size=48  zone: DefaultMallocZone_0x1011d6000
      	0x00ed6d30 0x00000001 0x00022320 0x00006100 	0m...... #...a..
      	0x00022560 0x00006100 0x00ed6d30 0x00000001 	`%...a..0m......
      	0x00ed7508 0x00000001 0x00ed6d30 0x00000001 	.u......0m......
      Leak: 0x610000045d00  size=48  zone: DefaultMallocZone_0x1011d6000
      	0x00000001 0x00000013 0x00000014 0x00000000 	................
      	0x00000018 0x00000000 0x6f43715f 0x4d616f63 	........_qCocoaM
      	0x41756e65 0x7365636e 0x00726f74 0x00000000 	enuAncestor.....
      Leak: 0x610000085280  size=80  zone: DefaultMallocZone_0x1011d6000
      	0x000c7380 0x00006100 0x00000000 0x00000000 	.s...a..........
      	0x0002a040 0x00000001 0x00000000 0x00000000 	@...............
      	0x00000000 0x00000000 0x5fbff2f8 0x00007fff 	..........._....
      	0x00000000 0x00000000 0x00000001 0x00050005 	................
      	0x80000003 0x00000000 0x00000000 0x00000000 	................
      Leak: 0x6100000852d0  size=80  zone: DefaultMallocZone_0x1011d6000
      	0x000c7380 0x00006100 0x00000000 0x00000000 	.s...a..........
      	0x0002a040 0x00000001 0x00000000 0x00000000 	@...............
      	0x00085280 0x00006100 0x5fbff2f8 0x00007fff 	.R...a....._....
      	0x00000000 0x00000000 0x00000001 0x00030005 	................
      	0x80000004 0x00000000 0x00000000 0x00000000 	................
      Leak: 0x6100000a5f40  size=96  zone: DefaultMallocZone_0x1011d6000   NSMenuItem  ObjC  AppKit
      	0x7b68e938 0x00007fff 0x00000000 0x00000000 	8.h{............
      	0x00022de0 0x00006100 0x05924970 0x00000001 	.-...a..pI......
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      	0x00000000 0x00000000 0x058fefa9 0x00000001 	................
      	0x000c7380 0x00006100 0x00000010 0x80000001 	.s...a..........
      Leak: 0x6100000c7380  size=112  zone: DefaultMallocZone_0x1011d6000   QCocoaMenuItem  C++  libqcocoa.dylib
      	0x0591b120 0x00000001 0x000c73f0 0x00006100 	 ........s...a..
      	0x000a5f40 0x00006100 0x00066f00 0x00006100 	@_...a...o...a..
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      	0x00000000 0x00000000 0x00000101 0x00000000 	................
      	0x000a4980 0x00006080 0x00000000 0x00000000 	.I...`..........
      	0x00000001 0x00000000 0x00a671c0 0x00000001 	.........q......
      	0x00000000 0x00000000 0x000009f0 0x00006100 	.............a..
      Leak: 0x6100000c73f0  size=112  zone: DefaultMallocZone_0x1011d6000   QObjectPrivate  C++  QtCore
      	0x010b0500 0x00000001 0x000c7380 0x00006100 	.........s...a..
      	0x00000000 0x00000000 0x00ed7508 0x00000001 	.........u......
      	0x00000030 0x00000000 0x00000000 0x00000000 	0...............
      	0x00045ca0 0x00006100 0x000c4f30 0x00006000 	.\...a..0O...`..
      	0x000228a0 0x00006100 0x00000000 0x00000000 	.(...a..........
      	0x00000000 0x00000000 0x00000018 0x00000000 	................
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      Leak: 0x6100000e3780  size=128  zone: DefaultMallocZone_0x1011d6000
      	0x00000001 0x00000005 0x00000006 0x00000000 	................
      	0x00000018 0x00000000 0x00000000 0x00000000 	................
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      	0x00000000 0x00000000 0x00085280 0x00006100 	.........R...a..
      	0x00085280 0x00006100 0x000852d0 0x00006100 	.R...a...R...a..
      	0x000852d0 0x00006100 0x00000000 0x00000000 	.R...a..........
      	0x00000000 0x00000000 0x00000000 0x00000000 	................
      

      Attachments

        1. qactiontest.zip
          2 kB
          William Overall
        2. qcocoamenu_leak_fix.diff
          0.5 kB
          Qt Support
        3. Screen Shot 2015-03-11 at 10.34.41.png
          120 kB
          Qt Support
        For Gerrit Dashboard: QTBUG-39490
        # Subject Branch Project Status CR V

        Activity

          People

            qt.team.graphics.and.multimedia Qt Graphics Team
            wro William Overall
            Votes:
            5 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes