Preserve LastError when calling TlsGetValue

TlsGetValue has a semantic difference with pthread_getspecific, in that it
can return a non-error NULL value, so it always sets the LastError.
But allocator callers may not be expecting calling e.g. free() to change
the value of the last error, so preserve it.
This commit is contained in:
Mike Hommey 2015-03-04 10:54:10 +09:00 committed by Jason Evans
parent 7c46fd59cc
commit 4d871f73af

View File

@ -277,9 +277,11 @@ a_name##tsd_set(a_type *val) \
a_attr bool \ a_attr bool \
a_name##tsd_cleanup_wrapper(void) \ a_name##tsd_cleanup_wrapper(void) \
{ \ { \
a_name##tsd_wrapper_t *wrapper; \ DWORD error = GetLastError(); \
a_name##tsd_wrapper_t *wrapper = (a_name##tsd_wrapper_t *) \
TlsGetValue(a_name##tsd_tsd); \
SetLastError(error); \
\ \
wrapper = (a_name##tsd_wrapper_t *)TlsGetValue(a_name##tsd_tsd);\
if (wrapper == NULL) \ if (wrapper == NULL) \
return (false); \ return (false); \
if (a_cleanup != malloc_tsd_no_cleanup && \ if (a_cleanup != malloc_tsd_no_cleanup && \
@ -307,8 +309,10 @@ a_name##tsd_wrapper_set(a_name##tsd_wrapper_t *wrapper) \
a_attr a_name##tsd_wrapper_t * \ a_attr a_name##tsd_wrapper_t * \
a_name##tsd_wrapper_get(void) \ a_name##tsd_wrapper_get(void) \
{ \ { \
DWORD error = GetLastError(); \
a_name##tsd_wrapper_t *wrapper = (a_name##tsd_wrapper_t *) \ a_name##tsd_wrapper_t *wrapper = (a_name##tsd_wrapper_t *) \
TlsGetValue(a_name##tsd_tsd); \ TlsGetValue(a_name##tsd_tsd); \
SetLastError(error); \
\ \
if (unlikely(wrapper == NULL)) { \ if (unlikely(wrapper == NULL)) { \
wrapper = (a_name##tsd_wrapper_t *) \ wrapper = (a_name##tsd_wrapper_t *) \