Preserve Win32 last error in wxTlsKey::Get()

::TlsGetValue() resets the last error code which means that the previous last
error is lost, but it shouldn't as we might be in the middle of logging it
with wxLogSysError(). So preserve the last error explicitly.

Closes #17209.
This commit is contained in:
Vadim Zeitlin
2015-10-16 20:20:42 +02:00
parent fdab57f4a4
commit 5e29b26d9e

View File

@@ -34,7 +34,14 @@ public:
// get the key value, there is no error return
void *Get() const
{
return ::TlsGetValue(m_slot);
// Exceptionally, TlsGetValue() calls SetLastError() even on success
// which means it overwrites the previous value. This is undesirable
// here, so explicitly preserve the last error here.
const DWORD dwLastError = ::GetLastError();
void* const value = ::TlsGetValue(m_slot);
if ( dwLastError )
::SetLastError(dwLastError);
return value;
}
// change the key value, return true if ok