From 01a08c5e47ac1bfd5054dfd6c0149b5500842bb7 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 23 Jul 2011 11:46:57 +0000 Subject: [PATCH] [KERNEL32] Bug #43: ConvertFiberToThread should return ERROR_ALREADY_THREAD, not ERROR_INVALID_PARAMETER in case of failure. Bug #44: ConvertFiberToThread should set FiberData to NULL in the TEB, after doing the conversion. Thanks, Winetests, for saying "0 failures", when this API was broken. svn path=/trunk/; revision=52803 --- reactos/dll/win32/kernel32/client/fiber.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/reactos/dll/win32/kernel32/client/fiber.c b/reactos/dll/win32/kernel32/client/fiber.c index ae32fd59539..1aa20eaf743 100644 --- a/reactos/dll/win32/kernel32/client/fiber.c +++ b/reactos/dll/win32/kernel32/client/fiber.c @@ -59,24 +59,27 @@ BOOL WINAPI ConvertFiberToThread(VOID) { - PTEB pTeb = NtCurrentTeb(); + PTEB Teb; + PFIBER FiberData; DPRINT1("Converting Fiber to Thread\n"); - /* the current thread isn't running a fiber: failure */ - if (!pTeb->HasFiberData) + /* Check if the thread is already not a fiber */ + Teb = NtCurrentTeb(); + if (!Teb->HasFiberData) { - SetLastError(ERROR_INVALID_PARAMETER); + /* Fail */ + SetLastError(ERROR_ALREADY_THREAD); return FALSE; } /* this thread won't run a fiber anymore */ - pTeb->HasFiberData = FALSE; + Teb->HasFiberData = FALSE; + FiberData = Teb->NtTib.FiberData; + Teb->NtTib.FiberData = NULL; - /* free the fiber */ - if(pTeb->NtTib.FiberData != NULL) - { - RtlFreeHeap(GetProcessHeap(), 0, pTeb->NtTib.FiberData); - } + /* Free the fiber */ + ASSERT(FiberData != NULL); + RtlFreeHeap(GetProcessHeap(), 0, FiberData); /* success */ return TRUE;