[PATCH v2 2/3] msvcrt: Don't lock the heap in operator_new

Martin Storsjo martin at martin.st
Fri Nov 6 06:51:56 CST 2015


The native msvcrt/msvcp allow two threads to be calling
the new handler simultaneously.

Try to avoid race conditions with set_new_handler by
storing the handler in a local variable.

Signed-off-by: Martin Storsjo <martin at martin.st>
---
 dlls/msvcrt/heap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/dlls/msvcrt/heap.c b/dlls/msvcrt/heap.c
index 02e69fe..a908846 100644
--- a/dlls/msvcrt/heap.c
+++ b/dlls/msvcrt/heap.c
@@ -131,6 +131,7 @@ void* CDECL MSVCRT_operator_new(MSVCRT_size_t size)
 {
   void *retval;
   int freed;
+  MSVCRT_new_handler_func handler;
 
   do
   {
@@ -141,12 +142,11 @@ void* CDECL MSVCRT_operator_new(MSVCRT_size_t size)
       return retval;
     }
 
-    LOCK_HEAP;
-    if(MSVCRT_new_handler)
-      freed = (*MSVCRT_new_handler)(size);
+    handler = MSVCRT_new_handler;
+    if(handler)
+      freed = (*handler)(size);
     else
       freed = 0;
-    UNLOCK_HEAP;
   } while(freed);
 
   TRACE("(%ld) out of memory\n", size);
-- 
1.8.1.2




More information about the wine-patches mailing list