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

QThreadStorage destruction with wrong destructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.2.4
    • Core: Threads
    • None
    • Linux/Other display system

    Description

      Hi,

      I have an issue on a Linux computer with the following gdb session. As you can see, I have a QThreadStorage<unsigned int> which behave as expected. Then I have some tests that use a TcpSocket to connect to a server. When tests are finished the QCoreApplication stop and do some cleanup. During this cleanup the QThreadStorage got deleted but for some reason it is not destructed by the right destructor. It is previously static_cast as a QNetworkAccessCache which is probably bigger than my unsigned int, thus a segfault arrive.

      The Logger class comes from a first shared library (named A) that contains the QThreadStorage<unsigned int> as a static variable. A second shared library do some Network stuff and is linked against A, Qt6Core and Qt6Network.

      The QThreadStorage<unsigned int> is a static variable living in the A library and used before main and thus QCoreApplication creation.

      The same code execute well on a Windows platform and on a Linux platform using Qt 5.12.12. It also fails on a QNX computer with Qt 6.2.4

      (gdb) watch *0x55555561a3b0
      Hardware watchpoint 1: *0x55555561a3b0
      (gdb) r
      Starting program: tests/Test_****/bin/Debug/Test_****
      [Thread debugging using libthread_db enabled]
      Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
      Hardware watchpoint 1: *0x55555561a3b0Old value = <unreadable>
      New value = -147850272
      _int_malloc (av=av@entry=0x7ffff72ffb80 <main_arena>, bytes=bytes@entry=24) at malloc.c:3767
      3767    malloc.c: No such file or directory.
      (gdb) c
      Continuing.
      Hardware watchpoint 1: *0x55555561a3b0
      Old value = -147850272
      New value = 0
      0x00007ffff7cdacf2 in qThreadStorage_localData<unsigned int> (d=...) at /home/it/Qt/6.2.4/gcc_64/include/QtCore/qthreadstorage.h:100
      100         if (!v) v = d.set(new T());
      (gdb) c
      Continuing.
      Hardware watchpoint 1: *0x55555561a3b0
      Old value = 0
      New value = 1
      Logger::process (this=0x555555617c30, p_message=...) at ****/source/log/Logger.cpp:25
      25      ****/source/log/Logger.cpp: No such file or directory.
      (gdb) c
      Continuing.
      Hardware watchpoint 1: *0x55555561a3b0
      Old value = 1
      New value = 0
      0x00007ffff7cd980f in Logger::process (this=0x555555617c30, p_message=...) at ****/source/log/Logger.cpp:55
      55      in ****/source/log/Logger.cpp
      (gdb) c
      Continuing.
      ********* Start testing of Test_**** *********
      Config: Using QtTest library 6.2.4, Qt 6.2.4 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)), ubuntu 20.04
      …
      PASS   : Test_****::cleanupTestCase()
      Totals: 146 passed, 0 failed, 0 skipped, 0 blacklisted, 9ms
      ********* Finished testing of Test_**** *********
      Program received signal SIGSEGV, Segmentation fault.
      0x00007ffff705a558 in qThreadStorage_deleteData<QNetworkAccessCache> (d=0x55555561a3b0)
          at /home/qt/work/qt/qtbase/include/QtCore/../../src/corelib/thread/qthreadstorage.h:134
      134     /home/qt/work/qt/qtbase/include/QtCore/../../src/corelib/thread/qthreadstorage.h: No such file or directory.
      (gdb) bt
      #0  0x00007ffff705a558 in qThreadStorage_deleteData<QNetworkAccessCache> (d=0x55555561a3b0)
          at /home/qt/work/qt/qtbase/include/QtCore/../../src/corelib/thread/qthreadstorage.h:134
      #1  QThreadStorage<QNetworkAccessCache*>::deleteData (x=0x55555561a3b0) at /home/qt/work/qt/qtbase/include/QtCore/../../src/corelib/thread/qthreadstorage.h:135
      #2  0x00007ffff77f31f0 in QThreadStorageData::finish (p=p@entry=0x555555617970) at /home/qt/work/qt/qtbase/src/corelib/thread/qthreadstorage.cpp:200
      #3  0x00007ffff766582d in QCoreApplicationPrivate::cleanupThreadData (this=this@entry=0x55555561a270)
          at /home/qt/work/qt/qtbase/src/corelib/kernel/qcoreapplication.cpp:503
      #4  0x00007ffff766599a in QCoreApplicationPrivate::~QCoreApplicationPrivate (this=0x55555561a270, __in_chrg=<optimized out>)
          at /home/qt/work/qt/qtbase/src/corelib/kernel/qcoreapplication.cpp:486
      #5  0x00007ffff7665aa9 in QCoreApplicationPrivate::~QCoreApplicationPrivate (this=0x55555561a270, __in_chrg=<optimized out>)
          at /home/qt/work/qt/qtbase/src/corelib/kernel/qcoreapplication.cpp:483
      #6  0x00005555555d8661 in main (argc=1, argv=0x7fffffffe398) at tests/Test_****/Test_****.cpp:1837
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            vivien delmon Vivien Delmon
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes