Fix strerror thread-safety issue - use strerror_r
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 13 Dec 2018 08:54:36 +0000 (11:54 +0300)
committerPetr Bred/AI Ecosystem Lab /SRR/Staff Engineer/삼성전자 <p.bred@samsung.com>
Thu, 13 Dec 2018 10:01:39 +0000 (13:01 +0300)
src/profiler.cpp

index 90654a135575e3eae877ca3367ae93a2da73e5d6..cf041d9253b2b21ac9eeaba22a197c197f05e6a1 100644 (file)
@@ -206,10 +206,18 @@ HRESULT Profiler::HandleException(const std::exception &e) const noexcept
         }
         else if (p_ios_base_failure)
         {
+            char buf[1024] = {0};
+            char *errno_msg;
+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+            int ret = strerror_r(errno, buf, sizeof(buf));
+            errno_msg = ret == 0 ? buf : "<strerror_r failure>";
+#else
+            errno_msg = strerror_r(errno, buf, sizeof(buf));
+#endif
             // std::ios_base::failure should be inherited from std::system_error
             // for C++11. This workaround applied if it is not true.
             LOG().Error() << "Exception: " << p_ios_base_failure->what() << ": "
-                << strerror(errno);
+                << errno_msg;
         }
         else
         {