Nikolay Sivov : ole32: Improve locking safety in IMalloc::Free().
Alexandre Julliard
julliard at winehq.org
Mon Apr 20 15:48:19 CDT 2020
Module: wine
Branch: master
Commit: da5903e7d17ab8af0ba0a2df395b13650123d712
URL: https://source.winehq.org/git/wine.git/?a=commit;h=da5903e7d17ab8af0ba0a2df395b13650123d712
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Mon Apr 20 10:59:19 2020 +0300
ole32: Improve locking safety in IMalloc::Free().
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ole32/ifs.c | 48 ++++++++++++++++++++++++++----------------------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c
index dfced20de2..f1dae0c956 100644
--- a/dlls/ole32/ifs.c
+++ b/dlls/ole32/ifs.c
@@ -254,35 +254,39 @@ static void * WINAPI IMalloc_fnRealloc(IMalloc *iface, void *pv, SIZE_T cb)
/******************************************************************************
* IMalloc32_Free [VTABLE]
*/
-static void WINAPI IMalloc_fnFree(IMalloc *iface, void *pv)
+static void WINAPI IMalloc_fnFree(IMalloc *iface, void *mem)
{
- BOOL fSpyed = FALSE;
-
- TRACE("(%p)\n",pv);
-
- if(!pv)
- return;
+ BOOL spyed_block = FALSE, spy_active = FALSE;
- if(Malloc32.pSpy) {
- EnterCriticalSection(&IMalloc32_SpyCS);
- fSpyed = mallocspy_remove_spyed_memory(pv);
- pv = IMallocSpy_PreFree(Malloc32.pSpy, pv, fSpyed);
- }
+ TRACE("(%p)\n", mem);
- HeapFree(GetProcessHeap(),0,pv);
+ if (!mem)
+ return;
- if(Malloc32.pSpy) {
- IMallocSpy_PostFree(Malloc32.pSpy, fSpyed);
+ if (Malloc32.pSpy)
+ {
+ EnterCriticalSection(&IMalloc32_SpyCS);
+ spyed_block = mallocspy_remove_spyed_memory(mem);
+ spy_active = TRUE;
+ mem = IMallocSpy_PreFree(Malloc32.pSpy, mem, spyed_block);
+ }
- /* check if can release the spy */
- if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) {
- IMallocSpy_Release(Malloc32.pSpy);
- Malloc32.SpyReleasePending = FALSE;
- Malloc32.pSpy = NULL;
- }
+ HeapFree(GetProcessHeap(), 0, mem);
- LeaveCriticalSection(&IMalloc32_SpyCS);
+ if (spy_active)
+ {
+ IMallocSpy_PostFree(Malloc32.pSpy, spyed_block);
+
+ /* check if can release the spy */
+ if (Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft)
+ {
+ IMallocSpy_Release(Malloc32.pSpy);
+ Malloc32.SpyReleasePending = FALSE;
+ Malloc32.pSpy = NULL;
}
+
+ LeaveCriticalSection(&IMalloc32_SpyCS);
+ }
}
/******************************************************************************
More information about the wine-cvs
mailing list