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

Memory leak in QFontCache

    XMLWordPrintable

Details

    • 36cb3f3f655a9090c82de609010cbfb88651a0f3

    Description

      Sometimes I got memory leaks in QtGui (QtGui compiled with vs2010 and 'visual leak detector vld' included)

      The reason is in function 'void QFontCache::timerEvent(QTimerEvent *)' in module 'qfont.cpp'

      if (-it.value().data>cache_count == 0)

      { FC_DEBUG(" DELETE: last occurrence in cache"); decreaseCost(it.value().data->cache_cost); delete it.value().data; }

      else

      { /* this particular font engine is in the cache multiple times... set current_cost to zero, so that we can keep looping to get rid of all occurrences */ current_cost = 0; }

      engineCache.erase(it);

      Sometimes 'cache_count' is > 0 but font engine is !!not!! multiple times in cache, so the engine is erased from the cache, but the data is not deleted.

      The reason for this could be in function 'void QFontDatabase::load(const QFontPrivate *d, int script)' in module 'qfontdatabase_win.cpp'

      QFontEngine *fe = QFontCache::instance()->findEngine(key);
      .
      .
      .
      QFontCache::instance()->insertEngine(key, fe);

      if 'fe' was found in the cache, no attemped should be made to insert it into the cache, because this will fail but 'cache_count' is inreased anyway.

      In constructor of class 'QFontEngineDirectWrite' in module 'qfontenginedirectWrite.cpp' the member variable 'cache_cost' is not initialized.
      It could be done with this rough estimate:

      .
      .
      collectMetrics();
      cache_cost = (m_ascent.toInt() + m_descent.toInt()) * m_xHeight.toInt() * 2000;

      In function 'initFontInfo' in module 'qfontdatabase_win.cpp' I think you have to release the 'fontFamily' too (is done in Microsoft example).

      .
      .
      delete[] name;
      if (familyNames != 0)
      familyNames->Release();
      if (fontFamily != 0)
      fontFamily->Release();

      Attachments

        1. leak_test.zip
          3 kB
          Arndt Stedler
        2. QTBUG-26861_after_patch.png
          31 kB
          Arndt Stedler
        3. QTBUG-26861_before_patch.png
          25 kB
          Arndt Stedler
        4. QTBUG-26861_for_QT4.8.4.patch
          1 kB
          Arndt Stedler
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ritt.ks Konstantin Ritt
            niels Niels Franksen
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes