diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index ead4a7ef63..e36cb20805 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -2772,6 +2772,7 @@ void MainWindow::loadContent(const QHash &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 &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 &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 &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),