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:
@@ -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
|
||||
|
Reference in New Issue
Block a user