From 9832f0ab857904a88c9b5e71a9e447abbebca8fb Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 15 Feb 2017 09:38:28 +0100 Subject: [PATCH] Copy argv[0] to prevent it pointing to invalid memory later If QCoreApplication is recreated, it is possible the previous argv[0] pointer has become invalid, so we should not rely on it. So to prevent that, we copy the original argv[0] to a static QByteArray. Task-number: QTBUG-58919 Change-Id: Idadd4cb78e4281830165fb681ea7925109f316ff Reviewed-by: Edward Welbourne Reviewed-by: Friedemann Kleint --- src/corelib/kernel/qcoreapplication.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index bf423cef21..db40b37da9 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2149,11 +2149,11 @@ QString QCoreApplication::applicationFilePath() QCoreApplicationPrivate *d = self->d_func(); if (d->argc) { - static const char *procName = d->argv[0]; - if (qstrcmp(procName, d->argv[0]) != 0) { + static QByteArray procName = QByteArray(d->argv[0]); + if (procName != d->argv[0]) { // clear the cache if the procname changes, so we reprocess it. QCoreApplicationPrivate::clearApplicationFilePath(); - procName = d->argv[0]; + procName = QByteArray(d->argv[0]); } }