::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)