Skip to content

Commit

Permalink
App: Consider using getpwuid_r(...) instead of getpwuid(...) for impr…
Browse files Browse the repository at this point in the history
…oved thread safety. [runtime/threadsafe_fn]
  • Loading branch information
wwmayer committed Sep 25, 2022
1 parent e2a552a commit 198ce19
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/App/Application.cpp
Expand Up @@ -2912,10 +2912,15 @@ QString getUserHome()
QString path;
#if defined(FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_BSD) || defined(FC_OS_MACOSX)
// Default paths for the user specific stuff
struct passwd *pwd = getpwuid(getuid());
if (!pwd)
struct passwd pwd;
struct passwd *result;
const std::size_t buflen = 16384;
std::vector<char> buffer(buflen);
int error = getpwuid_r(getuid(), &pwd, buffer.data(), buffer.size(), &result);
Q_UNUSED(error)
if (!result)
throw Base::RuntimeError("Getting HOME path from system failed!");
path = QString::fromUtf8(pwd->pw_dir);
path = QString::fromUtf8(result->pw_dir);
#else
path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#endif
Expand Down

0 comments on commit 198ce19

Please sign in to comment.