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

incorrect resources clean up code

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.13
    • Core: Other
    • None
    • All

    Description

      When static build version qt framework is link to a program, and

      the program create the application procedure like this:

      +fun main:

          | +fun create_app:

              |+ new QApplication

              |+ new QWidget

         ................

         |+ fun delete_app:

              |- delete QWidget

          |- delete QApplication 

      crash will happen in the delete application part.

      When I trace back the crash, I found there are several

      incorrect resources clean up code for some static global

      variables.

      This kind of error happened in this way:

      +fun main:

          | +fun create_app:

              |+ new QApplication(xxxx, xxx)

                 |+ (1) static variable created

              |+ new QWidget(xxxx, xxx)

         ................

         |+ fun delete_app:

              |+ delete QWidget

                   |+ (2) static variable released automatically !!!

              |+ delete QApplication

                   |+ (3) call_res_clean_up_fun_without_check !!!!

       

      For my application, I locate this kind bug in 3 files, and my patch is like this:

       

      diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
      index 80fa65daac..0166a06abe 100644
      --- a/src/gui/image/qicon.cpp
      +++ b/src/gui/image/qicon.cpp
      @@ -121,7 +121,10 @@ Q_GLOBAL_STATIC(IconCache, qtIconCache)
       
       static void qt_cleanup_icon_cache()
       {
      - qtIconCache()->clear();
      + IconCache* cache = qtIconCache();
      + if( cache ){
      + qtIconCache()->clear();
      + }
       }
       
       /*! \internal
      diff --git a/src/gui/kernel/qtouchdevice.cpp b/src/gui/kernel/qtouchdevice.cpp
      index 511e92566e..371f2e9326 100644
      --- a/src/gui/kernel/qtouchdevice.cpp
      +++ b/src/gui/kernel/qtouchdevice.cpp
      @@ -208,8 +208,10 @@ static QBasicMutex devicesMutex;
       static void cleanupDevicesList()
       {
       QMutexLocker lock(&devicesMutex);
      - qDeleteAll(*deviceList());
      - deviceList()->clear();
      + if (deviceList()){
      + qDeleteAll(*deviceList());
      + deviceList()->clear();
      + }
       }
       
       /*!
      diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp
      index f56be55325..507d8384da 100644
      --- a/src/gui/painting/qbrush.cpp
      +++ b/src/gui/painting/qbrush.cpp
      @@ -167,7 +167,9 @@ Q_GLOBAL_STATIC(QBrushPatternImageCache, qt_brushPatternImageCache)
       
       static void qt_cleanup_brush_pattern_image_cache()
       {
      - qt_brushPatternImageCache()->cleanup();
      + if(qt_brushPatternImageCache()) {
      + qt_brushPatternImageCache()->cleanup();
      + }
       }
       
       Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert)
      diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
      index fe7dd80e44..58e4ac8cbd 100644
      --- a/src/gui/text/qfontdatabase.cpp
      +++ b/src/gui/text/qfontdatabase.cpp
      @@ -2620,6 +2620,9 @@ bool QFontDatabase::removeAllApplicationFonts()
       QMutexLocker locker(fontDatabaseMutex());
       
       QFontDatabasePrivate *db = privateDb();
      + if (!db) {
      + return true;
      + }
       if (db->applicationFonts.isEmpty())
       return false;
      

      please check it.

      thanks a lot!

      Attachments

        1. diff.patch
          2 kB
        2. sample.cxx
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            josephshen Joseph Shen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes