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 <edward.welbourne@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Andy Shaw 2017-02-15 09:38:28 +01:00 committed by Paul Olav Tvete
parent 6a2609f379
commit 9832f0ab85

View File

@ -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]);
}
}