]> git.mxchange.org Git - flightgear.git/commitdiff
QtLauncher::initApp: store argc to avoid crash
authorRebecca N. Palmer <rebecca_palmer@zoho.com>
Sun, 22 Nov 2015 21:05:09 +0000 (21:05 +0000)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Sun, 22 Nov 2015 21:05:09 +0000 (21:05 +0000)
As QApplication only stores a reference to argc, it may crash if
the argc passed to it goes out of scope.  (One way to trigger this
is to pass an invalid --fg-root, triggering an initApp call from
Options::setupRoot.)  Copy argc to prevent this.

src/GUI/QtLauncher.cxx

index bb10cba74a3bc258ab9e5838d46abc4737554f8b..d16479e83bc1bc8be095fffbc850a2488386effc 100644 (file)
@@ -551,10 +551,14 @@ QtLauncher::~QtLauncher()
 void QtLauncher::initApp(int& argc, char** argv)
 {
     static bool qtInitDone = false;
+    static int s_argc;
     if (!qtInitDone) {
         qtInitDone = true;
+        s_argc = argc; // QApplication only stores a reference to argc,
+        // and may crash if it is freed
+        // http://doc.qt.io/qt-5/qguiapplication.html#QGuiApplication
 
-        QApplication* app = new QApplication(argc, argv);
+        QApplication* app = new QApplication(s_argc, argv);
         app->setOrganizationName("FlightGear");
         app->setApplicationName("FlightGear");
         app->setOrganizationDomain("flightgear.org");