[PATCH 1/5] ole32: Do not allocate spyed memory array on freeing attempts.
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- dlls/ole32/ifs.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c index 1b19be424c..dfced20de2 100644 --- a/dlls/ole32/ifs.c +++ b/dlls/ole32/ifs.c @@ -128,22 +128,19 @@ static void** mallocspy_is_allocation_spyed(const void *mem) return current; } -static BOOL RemoveMemoryLocation(LPCVOID pMem) +static BOOL mallocspy_remove_spyed_memory(const void *mem) { - LPVOID * Current; + void **current; - /* allocate the table if not already allocated */ - if (!Malloc32.SpyedBlockTableLength && !SetSpyedBlockTableLength(0x1000)) - return FALSE; + if (!Malloc32.SpyedBlockTableLength) + return FALSE; - if (!(Current = mallocspy_is_allocation_spyed(pMem))) - return FALSE; + if (!(current = mallocspy_is_allocation_spyed(mem))) + return FALSE; - /* location found */ - Malloc32.SpyedAllocationsLeft--; - /*TRACE("%lu\n",Malloc32.SpyedAllocationsLeft);*/ - *Current = NULL; - return TRUE; + Malloc32.SpyedAllocationsLeft--; + *current = NULL; + return TRUE; } /****************************************************************************** @@ -216,7 +213,7 @@ static void * WINAPI IMalloc_fnRealloc(IMalloc *iface, void *pv, SIZE_T cb) BOOL fSpyed; EnterCriticalSection(&IMalloc32_SpyCS); - fSpyed = RemoveMemoryLocation(pv); + fSpyed = mallocspy_remove_spyed_memory(pv); cb = IMallocSpy_PreRealloc(Malloc32.pSpy, pv, cb, &pRealMemory, fSpyed); /* check if can release the spy */ @@ -268,7 +265,7 @@ static void WINAPI IMalloc_fnFree(IMalloc *iface, void *pv) if(Malloc32.pSpy) { EnterCriticalSection(&IMalloc32_SpyCS); - fSpyed = RemoveMemoryLocation(pv); + fSpyed = mallocspy_remove_spyed_memory(pv); pv = IMallocSpy_PreFree(Malloc32.pSpy, pv, fSpyed); } -- 2.25.1
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- 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); + } } /****************************************************************************** -- 2.25.1
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- dlls/ole32/ifs.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c index f1dae0c956..96977fc751 100644 --- a/dlls/ole32/ifs.c +++ b/dlls/ole32/ifs.c @@ -363,17 +363,22 @@ static INT WINAPI IMalloc_fnDidAlloc(IMalloc *iface, void *mem) */ static void WINAPI IMalloc_fnHeapMinimize(IMalloc *iface) { - TRACE("()\n"); + BOOL spy_active = FALSE; - if(Malloc32.pSpy) { - EnterCriticalSection(&IMalloc32_SpyCS); - IMallocSpy_PreHeapMinimize(Malloc32.pSpy); - } + TRACE("()\n"); - if(Malloc32.pSpy) { - IMallocSpy_PostHeapMinimize(Malloc32.pSpy); - LeaveCriticalSection(&IMalloc32_SpyCS); - } + if (Malloc32.pSpy) + { + EnterCriticalSection(&IMalloc32_SpyCS); + spy_active = TRUE; + IMallocSpy_PreHeapMinimize(Malloc32.pSpy); + } + + if (spy_active) + { + IMallocSpy_PostHeapMinimize(Malloc32.pSpy); + LeaveCriticalSection(&IMalloc32_SpyCS); + } } static const IMallocVtbl VT_IMalloc32 = -- 2.25.1
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- dlls/ole32/ifs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c index 96977fc751..62007800e3 100644 --- a/dlls/ole32/ifs.c +++ b/dlls/ole32/ifs.c @@ -49,7 +49,6 @@ static const IMallocVtbl VT_IMalloc32; typedef struct { IMalloc IMalloc_iface; - DWORD dummy; /* nothing, we are static */ IMallocSpy * pSpy; /* the spy when active */ DWORD SpyedAllocationsLeft; /* number of spyed allocations left */ BOOL SpyReleasePending; /* CoRevokeMallocSpy called with spyed allocations left*/ @@ -58,7 +57,7 @@ typedef struct { } _Malloc32; /* this is the static object instance */ -static _Malloc32 Malloc32 = {{&VT_IMalloc32}, 0, NULL, 0, 0, NULL, 0}; +static _Malloc32 Malloc32 = {{&VT_IMalloc32}, NULL, 0, 0, NULL, 0}; /* with a spy active all calls from pre to post methods are threadsafe */ static CRITICAL_SECTION IMalloc32_SpyCS; -- 2.25.1
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com> --- dlls/ole32/ifs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c index 62007800e3..a144833c7a 100644 --- a/dlls/ole32/ifs.c +++ b/dlls/ole32/ifs.c @@ -47,17 +47,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(olemalloc); /* set the vtable later */ static const IMallocVtbl VT_IMalloc32; -typedef struct { +struct allocator +{ IMalloc IMalloc_iface; IMallocSpy * pSpy; /* the spy when active */ DWORD SpyedAllocationsLeft; /* number of spyed allocations left */ BOOL SpyReleasePending; /* CoRevokeMallocSpy called with spyed allocations left*/ LPVOID * SpyedBlocks; /* root of the table */ DWORD SpyedBlockTableLength;/* size of the table*/ -} _Malloc32; +}; -/* this is the static object instance */ -static _Malloc32 Malloc32 = {{&VT_IMalloc32}, NULL, 0, 0, NULL, 0}; +static struct allocator Malloc32 = { .IMalloc_iface.lpVtbl = &VT_IMalloc32 }; /* with a spy active all calls from pre to post methods are threadsafe */ static CRITICAL_SECTION IMalloc32_SpyCS; -- 2.25.1
participants (1)
-
Nikolay Sivov