Skip to content

Commit 36404ae

Browse files
committed
Merge #8540: qt: Fix random segfault when closing "Choose data directory" dialog
b4a9aa5 qt: Fix random segfault when closing "Choose data directory" dialog (Wladimir J. van der Laan)
2 parents 8250de1 + b4a9aa5 commit 36404ae

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/qt/bitcoin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ int main(int argc, char *argv[])
578578

579579
/// 5. Now that settings and translations are available, ask user for data directory
580580
// User language is set up: pick a data directory
581-
Intro::pickDataDirectory();
581+
if (!Intro::pickDataDirectory())
582+
return 0;
582583

583584
/// 6. Determine availability of data directory and parse bitcoin.conf
584585
/// - Do not call GetDataDir(true) before this step finishes

src/qt/intro.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ QString Intro::getDefaultDataDirectory()
165165
return GUIUtil::boostPathToQString(GetDefaultDataDir());
166166
}
167167

168-
void Intro::pickDataDirectory()
168+
bool Intro::pickDataDirectory()
169169
{
170170
namespace fs = boost::filesystem;
171171
QSettings settings;
172172
/* If data directory provided on command line, no need to look at settings
173173
or show a picking dialog */
174174
if(!GetArg("-datadir", "").empty())
175-
return;
175+
return true;
176176
/* 1) Default data directory for operating system */
177177
QString dataDir = getDefaultDataDirectory();
178178
/* 2) Allow QSettings to override default dir */
@@ -190,7 +190,7 @@ void Intro::pickDataDirectory()
190190
if(!intro.exec())
191191
{
192192
/* Cancel clicked */
193-
exit(0);
193+
return false;
194194
}
195195
dataDir = intro.getDataDirectory();
196196
try {
@@ -211,6 +211,7 @@ void Intro::pickDataDirectory()
211211
*/
212212
if(dataDir != getDefaultDataDirectory())
213213
SoftSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
214+
return true;
214215
}
215216

216217
void Intro::setStatus(int status, const QString &message, quint64 bytesAvailable)

src/qt/intro.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ class Intro : public QDialog
3535
/**
3636
* Determine data directory. Let the user choose if the current one doesn't exist.
3737
*
38+
* @returns true if a data directory was selected, false if the user cancelled the selection
39+
* dialog.
40+
*
3841
* @note do NOT call global GetDataDir() before calling this function, this
3942
* will cause the wrong path to be cached.
4043
*/
41-
static void pickDataDirectory();
44+
static bool pickDataDirectory();
4245

4346
/**
4447
* Determine default data directory for operating system.

0 commit comments

Comments
 (0)