From: Andre Heinecke <aheinecke@gnupg.org>
Date: Thu, 25 Jul 2019 14:20:51 +0200
Subject: qt: Fix use of dangling pointer in QApplication

* qt/main.cpp (main): Use a new variable for argc that stays
valid.
--
The QApplication constructor takes argc as a reference and the referenced
integer has to stay alive for at least as long as the QApplication.

GnuPG-Bug-Id: T4658
Based on a Patch from: Fabian Vogt <fvogt@suse.com>
Thanks!

(cherry picked from commit 0e2e53c8987d6f236aaef515eb005e8e86397fbc)
---
 qt/main.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/qt/main.cpp b/qt/main.cpp
index 70a009d..66d1ae9 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -312,6 +312,7 @@ main(int argc, char *argv[])
     pinentry_init("pinentry-qt");
 
     QApplication *app = NULL;
+    int new_argc = 0;
 
 #ifdef FALLBACK_CURSES
     if (!pinentry_have_display(argc, argv)) {
@@ -351,8 +352,15 @@ main(int argc, char *argv[])
                 p += strlen(argv[i]) + 1;
             }
 
-        i = argc;
-        app = new QApplication(i, new_argv);
+        /* Note: QApplication uses int &argc so argc has to be valid
+         * for the full lifetime of the application.
+         *
+         * As Qt might modify argc / argv we use copies here so that
+         * we do not loose options that are handled in both. e.g. display.
+         */
+        new_argc = argc;
+        Q_ASSERT (new_argc);
+        app = new QApplication(new_argc, new_argv);
         app->setWindowIcon(QIcon(QLatin1String(":/document-encrypt.png")));
     }
 
