aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-08-18 16:58:04 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2016-09-07 16:17:09 +0200
commit1db3352cc663f6a25a39813c763a2f6263f55e6d (patch)
tree07b488e23edec9725205de01d2f8527fde67336d /src
parent75f20652932361a176e72e2ba3477f4604810bb6 (diff)
downloadbitcoin-1db3352cc663f6a25a39813c763a2f6263f55e6d.tar.xz
qt: Fix random segfault when closing "Choose data directory" dialog
The `pickDataDirectory()` function was calling `exit(0)` to quit the application when the user closes the dialog without choosing a data directory. This is a bad idea because a background thread is created (to check free space on the drive of the currently selected datadir). The thread is not stopped and unwound properly, resulting in a potential race condition somewhere deep in Qt. So replace the `exit()` by a boolean return value, and let the stack unwind normally.
Diffstat (limited to 'src')
-rw-r--r--src/qt/bitcoin.cpp3
-rw-r--r--src/qt/intro.cpp7
-rw-r--r--src/qt/intro.h5
3 files changed, 10 insertions, 5 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 64b5c83d72..430e6dd0e8 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -578,7 +578,8 @@ int main(int argc, char *argv[])
/// 5. Now that settings and translations are available, ask user for data directory
// User language is set up: pick a data directory
- Intro::pickDataDirectory();
+ if (!Intro::pickDataDirectory())
+ return 0;
/// 6. Determine availability of data directory and parse bitcoin.conf
/// - Do not call GetDataDir(true) before this step finishes
diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp
index 6d6af54290..6a5740e21d 100644
--- a/src/qt/intro.cpp
+++ b/src/qt/intro.cpp
@@ -165,14 +165,14 @@ QString Intro::getDefaultDataDirectory()
return GUIUtil::boostPathToQString(GetDefaultDataDir());
}
-void Intro::pickDataDirectory()
+bool Intro::pickDataDirectory()
{
namespace fs = boost::filesystem;
QSettings settings;
/* If data directory provided on command line, no need to look at settings
or show a picking dialog */
if(!GetArg("-datadir", "").empty())
- return;
+ return true;
/* 1) Default data directory for operating system */
QString dataDir = getDefaultDataDirectory();
/* 2) Allow QSettings to override default dir */
@@ -190,7 +190,7 @@ void Intro::pickDataDirectory()
if(!intro.exec())
{
/* Cancel clicked */
- exit(0);
+ return false;
}
dataDir = intro.getDataDirectory();
try {
@@ -211,6 +211,7 @@ void Intro::pickDataDirectory()
*/
if(dataDir != getDefaultDataDirectory())
SoftSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
+ return true;
}
void Intro::setStatus(int status, const QString &message, quint64 bytesAvailable)
diff --git a/src/qt/intro.h b/src/qt/intro.h
index 9e2e96dc9e..ee768a7ad8 100644
--- a/src/qt/intro.h
+++ b/src/qt/intro.h
@@ -35,10 +35,13 @@ public:
/**
* Determine data directory. Let the user choose if the current one doesn't exist.
*
+ * @returns true if a data directory was selected, false if the user cancelled the selection
+ * dialog.
+ *
* @note do NOT call global GetDataDir() before calling this function, this
* will cause the wrong path to be cached.
*/
- static void pickDataDirectory();
+ static bool pickDataDirectory();
/**
* Determine default data directory for operating system.