diff --git a/src/Platform/Thread.h b/src/Platform/Thread.h index f0c45be5..b1152af5 100644 --- a/src/Platform/Thread.h +++ b/src/Platform/Thread.h @@ -64,7 +64,7 @@ namespace VeraCrypt return 0; } - static const size_t MinThreadStackSize = 1024 * 1024; + static const size_t MinThreadStackSize = 8 * 1024 * 1024; ThreadSystemHandle SystemHandle; diff --git a/src/Platform/Unix/Thread.cpp b/src/Platform/Unix/Thread.cpp index 47046eee..3bfcd956 100644 --- a/src/Platform/Unix/Thread.cpp +++ b/src/Platform/Unix/Thread.cpp @@ -18,6 +18,26 @@ namespace VeraCrypt { + namespace + { + struct PthreadAttr + { + PthreadAttr () + { + int status = pthread_attr_init (&Attr); + if (status != 0) + throw SystemException (SRC_POS, status); + } + + ~PthreadAttr () + { + pthread_attr_destroy (&Attr); + } + + pthread_attr_t Attr; + }; + } + void Thread::Join () const { int status = pthread_join (SystemHandle, nullptr); @@ -27,26 +47,22 @@ namespace VeraCrypt void Thread::Start (ThreadProcPtr threadProc, void *parameter) { - pthread_attr_t attr; + PthreadAttr attr; size_t stackSize = 0; int status; - status = pthread_attr_init (&attr); - if (status != 0) - throw SystemException (SRC_POS, status); - - status = pthread_attr_getstacksize (&attr, &stackSize); + status = pthread_attr_getstacksize (&attr.Attr, &stackSize); if (status != 0) throw SystemException (SRC_POS, status); if (stackSize < MinThreadStackSize) { - status = pthread_attr_setstacksize (&attr, MinThreadStackSize); + status = pthread_attr_setstacksize (&attr.Attr, MinThreadStackSize); if (status != 0) throw SystemException (SRC_POS, status); } - status = pthread_create (&SystemHandle, nullptr, threadProc, parameter); + status = pthread_create (&SystemHandle, &attr.Attr, threadProc, parameter); if (status != 0) throw SystemException (SRC_POS, status); }