From 6862249daaa8c37f017b1a84c515ca39c7ed67d3 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 9 Jul 2026 14:00:00 +0200 Subject: [PATCH] cmake-gui: Fix crash when selecting a preset with a differing build dir QCMake::setPreset() bound a reference to the selected preset's expanded data inside CMakePresetsGraph.ConfigurePresets and then called setBinaryDirectory(). When the selected preset's build directory holds a cache whose CMAKE_HOME_DIRECTORY differs from the current source directory (e.g. because the source path is reached through a symbolic link, since browsing keeps the link unresolved while the cache stores the real path), setBinaryDirectory() loads that cache and re-sets the source directory. That re-reads the presets graph via loadPresets(), which calls ClearPresets() and destroys the map entry, leaving the reference dangling. Subsequent access crashed with a use-after-free. Copy the expanded preset instead of holding a reference into the graph so it stays valid across setBinaryDirectory(). Fixes: #27927 --- Source/QtDialog/QCMake.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index eb743bc1e4..e05f3add20 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -164,7 +164,7 @@ void QCMake::setPreset(QString const& name, bool setBinary) if (!name.isNull()) { std::string presetName(name.toStdString()); - auto const& expandedPreset = + auto const expandedPreset = this->CMakePresetsGraph.ConfigurePresets[presetName].Expanded; if (expandedPreset) { if (setBinary && !expandedPreset->BinaryDir.empty()) {