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.

See #17209.

(this is a backport of 5e29b26d9e from master)
This commit is contained in:
Vadim Zeitlin
2015-10-16 20:20:42 +02:00
parent 56a3441663
commit e093a3b1b4

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