From 1066432dea26e894265df0e46b8c70130eec4b6d Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Wed, 7 Oct 2015 06:13:57 +0000 Subject: [PATCH 1/2] SEMLOCK.h: Add missing ESP adjustment Fixes strange fclose() return values --- src/INCLUDE/SEMLOCK.H | 1 + 1 file changed, 1 insertion(+) diff --git a/src/INCLUDE/SEMLOCK.H b/src/INCLUDE/SEMLOCK.H index a5c0c73..0743b7f 100644 --- a/src/INCLUDE/SEMLOCK.H +++ b/src/INCLUDE/SEMLOCK.H @@ -128,6 +128,7 @@ usDone: ; _asm {mov edx, Number} \ _asm {push edx} \ _asm {call _DestroySemaphore} \ + _asm {add esp, 4} \ usDone: ; #else From 80420e6175dfd2eda7da5731663833610fcec80e Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Wed, 7 Oct 2015 06:16:49 +0000 Subject: [PATCH 2/2] FPLOCK.C: Don't delete the semaphore on close The semaphore might be immediately reused by a file newly opened in another thread, thus creating a race condition. --- src/WIN32/FPLOCK.C | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/WIN32/FPLOCK.C b/src/WIN32/FPLOCK.C index 17475d8..ca1c5fc 100644 --- a/src/WIN32/FPLOCK.C +++ b/src/WIN32/FPLOCK.C @@ -80,12 +80,12 @@ void __fp_unlock(FILE *fp) { #if _MT int iIdx; - int bOpen, bDelete; +// int bOpen, bDelete; iIdx = (int)(fp - _iob) + _semFpBase; - bOpen = fp->_flag & (_IOREAD | _IOWRT | _IORW); /* Is File Open */ - bDelete = !bOpen; - - UnlockSemaphoreNested(iIdx, bDelete) +// bOpen = fp->_flag & (_IOREAD | _IOWRT | _IORW); /* Is File Open */ +// bDelete = !bOpen; +// UnlockSemaphoreNested(iIdx, bDelete) + UnlockSemaphoreNested(iIdx, 0) #endif }