Skip to content

Commit

Permalink
(Qt) Fix crash when loading content via desktop menu while content is…
Browse files Browse the repository at this point in the history
… already running (#13595)
  • Loading branch information
jdgleaver authored Feb 4, 2022
1 parent e541dd5 commit 412c798
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ui/drivers/ui_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 412c798

Please sign in to comment.