(Qt) Fix crash when loading content via desktop menu while content is already running (#13595)

This commit is contained in:
jdgleaver 2022-02-04 23:26:10 +00:00 committed by GitHub
parent e541dd5ab1
commit 412c79862c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2772,6 +2772,7 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
QByteArray contentDbNameArray;
QByteArray contentCrc32Array;
char contentDbNameFull[PATH_MAX_LENGTH];
char corePathCached[PATH_MAX_LENGTH];
const char *corePath = NULL;
const char *contentPath = NULL;
const char *contentLabel = NULL;
@ -2782,6 +2783,7 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
core_info_t *coreInfo = NULL;
contentDbNameFull[0] = '\0';
corePathCached[0] = '\0';
if (m_pendingRun)
coreSelection = CORE_SELECTION_CURRENT;
@ -2882,6 +2884,15 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
!string_is_empty(coreInfo->path))
corePath = coreInfo->path;
/* If a core is currently running, the following
* call of 'command_event(CMD_EVENT_UNLOAD_CORE, NULL)'
* will free the global core_info struct, which will
* in turn free the pointer referenced by coreInfo->path.
* This will invalidate corePath, so we have to cache
* its current value here. */
if (!string_is_empty(corePath))
strlcpy(corePathCached, corePath, sizeof(corePathCached));
/* Add lpl extension to db_name, if required */
if (!string_is_empty(contentDbName))
{
@ -2910,7 +2921,7 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
command_event(CMD_EVENT_UNLOAD_CORE, NULL);
if (!task_push_load_content_with_new_core_from_companion_ui(
corePath, contentPath, contentLabel, contentDbNameFull, contentCrc32,
corePathCached, contentPath, contentLabel, contentDbNameFull, contentCrc32,
&content_info, NULL, NULL))
{
QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR),