[glib: 1/2] win32: Check and avoid using TLS index 0
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] win32: Check and avoid using TLS index 0
- Date: Thu, 8 Jul 2021 11:27:18 +0000 (UTC)
commit 3364e0204150a7f38771a44dc46d4a1fc7084cdd
Author: Yongsu Park <pcpenpal gmail com>
Date: Wed May 13 17:29:13 2020 +0900
win32: Check and avoid using TLS index 0
Zero is a valid TLS index so it needs to be checked. It’s also the
integer used to indicate that no TLS has been allocated yet, so it can’t
be used as a TLS identifier.
Incorporates changes from Philip Withnall.
Fixes: #2058
glib/gthread-win32.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
---
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index 66558df4a..63e3cdd76 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -319,7 +319,17 @@ g_private_get_impl (GPrivate *key)
impl = TlsAlloc ();
- if (impl == TLS_OUT_OF_INDEXES)
+ if G_UNLIKELY (impl == 0)
+ {
+ /* Ignore TLS index 0 temporarily (as 0 is the indicator that we
+ * haven't allocated TLS yet) and alloc again;
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2058 */
+ DWORD impl2 = TlsAlloc ();
+ TlsFree (impl);
+ impl = impl2;
+ }
+
+ if (impl == TLS_OUT_OF_INDEXES || impl == 0)
g_thread_abort (0, "TlsAlloc");
if (key->notify != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]