From 332a9c67d3d400e6d127afce26f9e52114c50d5c Mon Sep 17 00:00:00 2001
From: Zebediah Figura <z.figura12@gmail.com>
Date: Sat, 28 Jul 2018 12:09:40 -0500
Subject: [PATCH 71/83] ntdll: Fix growing the shm_addrs array.

Fixes an issue exposed by the last patch and visible in GTA V. Presumably
this didn't show up earlier because applications usually don't create large
numbers of semaphores or mutexes, and previously events didn't use shared
memory.
---
 dlls/ntdll/esync.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/esync.c b/dlls/ntdll/esync.c
index 663b3658b..a94a5aa6e 100644
--- a/dlls/ntdll/esync.c
+++ b/dlls/ntdll/esync.c
@@ -143,8 +143,9 @@ static void *get_shm( unsigned int idx )
 
     if (entry >= shm_addrs_size)
     {
-        shm_addrs_size *= 2;
-        if (!(shm_addrs = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, shm_addrs, shm_addrs_size )))
+        shm_addrs_size = entry + 1;
+        if (!(shm_addrs = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
+                shm_addrs, shm_addrs_size * sizeof(shm_addrs[0]) )))
             ERR("Failed to grow shm_addrs array to size %d.\n", shm_addrs_size);
     }
 
-- 
2.20.1

