diff --git a/src/network/core/os_abstraction.cpp b/src/network/core/os_abstraction.cpp index 2e60100400267..b2d3475d01994 100644 --- a/src/network/core/os_abstraction.cpp +++ b/src/network/core/os_abstraction.cpp @@ -78,14 +78,14 @@ bool NetworkError::IsConnectInProgress() const */ const char *NetworkError::AsString() const { - if (this->message.get() == nullptr) { + if (this->message.empty()) { #if defined(_WIN32) char buffer[512]; if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, this->error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL) == 0) { seprintf(buffer, lastof(buffer), "Unknown error %d", this->error); } - this->message.reset(new std::string(buffer)); + this->message.assign(buffer); #else /* Make strerror thread safe by locking access to it. There is a thread safe strerror_r, however * the non-POSIX variant is available due to defining _GNU_SOURCE meaning it is not portable. @@ -94,10 +94,10 @@ const char *NetworkError::AsString() const * variant always fills the buffer. This makes the behaviour too erratic to work with. */ static std::mutex mutex; std::lock_guard guard(mutex); - this->message.reset(new std::string(strerror(this->error))); + this->message.assign(strerror(this->error)); #endif } - return this->message.get()->c_str(); + return this->message.c_str(); } /** diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index bedaf94569c2f..55d733501758f 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -20,8 +20,8 @@ */ class NetworkError { private: - int error; ///< The underlying error number from errno or WSAGetLastError. - mutable std::unique_ptr message; ///< The string representation of the error. + int error; ///< The underlying error number from errno or WSAGetLastError. + mutable std::string message; ///< The string representation of the error (set on first call to #AsString). public: NetworkError(int error);