From ee30a9aeb8db442a9cea52449959178f9d449d39 Mon Sep 17 00:00:00 2001
From: Paul Gofman <pgofman@codeweavers.com>
Date: Thu, 23 Apr 2020 15:00:48 +0300
Subject: [PATCH] kernelbase: Zero all FLS slots instances in FlsFree().

---
 dlls/kernelbase/thread.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/dlls/kernelbase/thread.c b/dlls/kernelbase/thread.c
index 0ba67e1b6c9..9a65630cca7 100644
--- a/dlls/kernelbase/thread.c
+++ b/dlls/kernelbase/thread.c
@@ -1137,7 +1137,6 @@ DWORD WINAPI DECLSPEC_HOTPATCH FlsAlloc( PFLS_CALLBACK_FUNCTION callback )
     return index;
 }
 
-
 /***********************************************************************
  *           FlsFree   (kernelbase.@)
  */
@@ -1148,11 +1147,17 @@ BOOL WINAPI DECLSPEC_HOTPATCH FlsFree( DWORD index )
     lock_fls_section();
     ret = RtlAreBitsSet( NtCurrentTeb()->Peb->FlsBitmap, index, 1 );
     if (ret) RtlClearBits( NtCurrentTeb()->Peb->FlsBitmap, index, 1 );
-    if (ret)
+    if (ret && NtCurrentTeb()->FlsSlots)
     {
-        /* FIXME: call Fls callback */
-        /* FIXME: add equivalent of ThreadZeroTlsCell here */
-        if (NtCurrentTeb()->FlsSlots) *fls_addr_from_index(NtCurrentTeb()->FlsSlots, index) = NULL;
+        LIST_ENTRY *entry;
+
+        for (entry = NtCurrentTeb()->Peb->FlsListHead.Flink;
+                entry != &NtCurrentTeb()->Peb->FlsListHead;
+                entry = entry->Flink)
+        {
+            /* FIXME: call Fls callback */
+            *fls_addr_from_index(entry, index) = NULL;
+        }
     }
     else SetLastError( ERROR_INVALID_PARAMETER );
     unlock_fls_section();
-- 
2.25.3

