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

Memory leak in qiconhelper.cpp when loading icon by name

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.15.3, 5.15.7, 6.2.0 Beta4, 6.3.0 Alpha
    • 5.15.0
    • GUI: Painting
    • None
    • Compiler: g++ 9.3.0
      Operating system: Linux (Ubuntu 20.04)
      Qt: 5.15.0 (downloaded from Qt)
    • All
    • 47ded88e0c2f489e112b72f62151123db5c04dbe (qt/qtdeclarative/dev) 2812a7bf5699d0e1fe6c2c9dae2915acfd3da791 (qt/tqtc-qtquickcontrols2/5.15) 0437dbfc8811ccd44128ef6b413d933930a98114 (qt/qtdeclarative/6.2)

    Description

      There appears to be a memory leak when loading an icon by name. This can be demonstrated with a simple program that alternates the icon on a button. This was detected because we do an ASAN compile during development. It leaks about 150 bytes per icon, but this will quickly add up when you consider ListViews with ItemDelegates that have an icon on them, especially as they potentially reload when you scroll up and down the list.

      QML:

       

      Item {
        property int d_count: 1
      		
        Timer {
          interval: 10
          repeat: true
          running: true
      
          onTriggered: ++d_count
        }
      
        CON2.ToolButton {
          anchors.centerIn: parent
          icon.name: (d_count % 2) == 0
            ? "edit-select-symbolic"
            : "error-correct-symbolic"
        }
      	
        Component.onDestruction: {
          console.log("count=" + d_count)
        }
      }

       

       

      main.cpp (probably not too relevant)

       

      //----------------------------------------------------------------------//
      int main(int argc, char** argv)
      {
        QCoreApplication::addLibraryPath("./3rdparty/qt5/plugins");
      
        QApplication app(argc, argv);	
      
        QQmlApplicationEngine engine;
        engine.addImportPath("qrc:///");
        engine.addImportPath("./3rdparty/qt5/qml");
        engine.load(QUrl("qrc:/APP_TEST_SQML/app_test_sqml_application.qml"));
        QApplication::exec();
        return 0;
      }
      

       

      The output of an ASAN build:

      [matthewf-dev4 trunk]$ ./qml_simpletestprog 
      qml: count=120
      
      =================================================================
      ==1322176==ERROR: LeakSanitizer: detected memory leaks
      
      Direct leak of 5760 byte(s) in 120 object(s) allocated from:
          #0 0x56296331e167 in operator new(unsigned long) (/.../qml_simpletestprog+0x14a167)
          #1 0x7f5794f898d1 in QIconLoader::findIconHelper(QString const&, QString const&, QStringList&) const (/.../sharedlib/libQt5Gui.so.5+0x2038d1)
      
      Indirect leak of 30836 byte(s) in 122 object(s) allocated from:
          #0 0x56296331c3e8 in __interceptor_malloc (/.../qml_simpletestprog+0x1483e8)
          #1 0x7f5795ce1f3c in QArrayData::allocate(unsigned long, unsigned long, unsigned long, QFlags<QArrayData::AllocationOption>) (/.../libQt5Core.so.5+0xbff3c)
      
      SUMMARY: AddressSanitizer: 36596 byte(s) leaked in 242 allocation(s).
      

      The leaks are proportional to the number of times the icon is alternated. To check this was not a false positive I ran a non-ASAN build and watched the memory usage with 'top' and it just kept climbing.

      The problem allocations are in QIconLoader::findIconHelper

       

      Attachments

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

        Activity

          People

            vgt Eirik Aavitsland
            matthewf Matthew Fincham
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes