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

Dependency between global static objects

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 3.x
    • None

      It's possible to have dependency between global static objects in qt,
      and if one is used from others destructor, depending on the destruction order, the application can segfault on exit.

      Here is the example which triggers this bug with QPluginLoader and qrand().
      QPluginLoaded saves plugins cache with QSettings in destructor of internal global static object
      (which calls QMap::insert() and qrand() for large enough maps):

      int main(int argc, char* argv[])
      {
      QApplication app(argc, argv);
      QPluginLoader loader("./libphononengine.so");
      loader.load();
      qrand();
      return 0;
      }

      The second example (attached) triggers the same bug, but it is easier to reproduce (doesn't require library and large enough settings file).

      The bug can be reproduced on linux and mac, where qrand() uses global static seeds storage,
      but is also possible with other combinations of global static objects.

        1. example2.cpp
          0.5 kB
          Dmytro Poplavskiy
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            stormols Marius Storm-Olsen
            poplavsk Dmytro Poplavskiy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes