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

Memory leak in QFontDatabase

    XMLWordPrintable

Details

    • Linux/X11
    • 4f730fc5f13b906d7bb2461f803ecedb4937c16d (qt/qtbase/dev) f00efd82334d16197ebe4f5a9c01f54ba8ba925e (qt/qtbase/6.1) 4b39f612615a63d421975a1869175a0c685c9293 (qt/qtbase/6.2) 7adcec5b8feeefdaffa4ee72d0b9c8e282e10f6a (qt/tqtc-qtbase/5.15)

    Description

      When checking our application for memory leaks, I encountered a problem with the memory handling in QFontDatabase that can already be seen with the following test case:

      #include <QApplication> 
      #include <QFontDatabase> 
      #include <QTimer> 
       
      int main(int argc, char **argv) 
      { 
          QApplication app(argc, argv); 
       
          const auto id = QFontDatabase::addApplicationFont(QStringLiteral("anyexistingfont.ttf")); 
          if (id == -1) 
              qWarning("Adding font failed"); 
       
          QTimer::singleShot(1000, qApp, &QApplication::quit); 
       
          const int status = app.exec(); 
       
          QFontDatabase::removeAllApplicationFonts(); 
       
          return status; 
      }

      I used valgrind with the --leak-check=full --show-leak-kinds=all options and encountered the following problem:

      ==44736== 30,720 bytes in 1 blocks are still reachable in loss record 291 of 291 
      ==44736==    at 0x4840D7B: realloc (vg_replace_malloc.c:834) 
      ==44736==    by 0x81C6854: FcFontSetAdd (in /usr/lib/libfontconfig.so.1.12.0) 
      ==44736==    by 0x81BB5F4: ??? (in /usr/lib/libfontconfig.so.1.12.0) 
      ==44736==    by 0x81BB80C: ??? (in /usr/lib/libfontconfig.so.1.12.0) 
      ==44736==    by 0x81BB8C9: FcConfigBuildFonts (in /usr/lib/libfontconfig.so.1.12.0) 
      ==44736==    by 0x81C7568: FcInitLoadConfigAndFonts (in /usr/lib/libfontconfig.so.1.12.0) 
      ==44736==    by 0x81B7D96: ??? (in /usr/lib/libfontconfig.so.1.12.0) 
      ==44736==    by 0x81B8B9C: FcConfigGetFonts (in /usr/lib/libfontconfig.so.1.12.0) 
      ==44736==    by 0x5851DF5: QFontconfigDatabase::addApplicationFont(QByteArray const&, QString const&, QFontDatabasePrivate::ApplicationFont*) (in /local/ssd/mlangen/build/a3gui.default/usr/lib/libQt6Gui.so.6.1.0) 
      ==44736==    by 0x56C6A8F: QFontDatabasePrivate::addAppFont(QByteArray const&, QString const&) (in /local/ssd/mlangen/build/a3gui.default/usr/lib/libQt6Gui.so.6.1.0) 
      ==44736==    by 0x56C6F93: QFontDatabase::addApplicationFont(QString const&) (in /local/ssd/mlangen/build/a3gui.default/usr/lib/libQt6Gui.so.6.1.0) 
      ==44736==    by 0x201F04: main (fontdatabase.cpp:9)

      I wonder if this memory could be freed somehow?

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            mlangen Marc Langenbach
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes