From d8aa85359679277fc332684d6f34cce6557a8a50 Mon Sep 17 00:00:00 2001 From: "Dimitrie O. Paun" Date: Wed, 26 Nov 2003 03:34:51 +0000 Subject: [PATCH] Fix the IMalloc::ReAlloc() to follow the documented behavior. --- dlls/ole32/ifs.c | 7 ++++++- dlls/ole32/ole16.c | 33 ++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c index 54b84d4b60d..e1b99a171f0 100644 --- a/dlls/ole32/ifs.c +++ b/dlls/ole32/ifs.c @@ -209,7 +209,12 @@ static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) { pv = pRealMemory; } - pNewMemory = HeapReAlloc(GetProcessHeap(),0,pv,cb); + if (!pv) pNewMemory = HeapAlloc(GetProcessHeap(),0,cb); + else if (cb) pNewMemory = HeapReAlloc(GetProcessHeap(),0,pv,cb); + else { + HeapFree(GetProcessHeap(),0,pv); + pNewMemory = NULL; + } if(Malloc32.pSpy) { pNewMemory = IMallocSpy_PostRealloc(Malloc32.pSpy, pNewMemory, TRUE); diff --git a/dlls/ole32/ole16.c b/dlls/ole32/ole16.c index 1b410332b1f..61e980e088d 100644 --- a/dlls/ole32/ole16.c +++ b/dlls/ole32/ole16.c @@ -112,19 +112,6 @@ SEGPTR WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) { return MapLS( HeapAlloc( GetProcessHeap(), 0, cb ) ); } -/****************************************************************************** - * IMalloc16_Realloc [COMPOBJ.504] - */ -SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb) -{ - SEGPTR ret; - ICOM_THIS(IMalloc16Impl,iface); - TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb); - ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) ); - UnMapLS(pv); - return ret; -} - /****************************************************************************** * IMalloc16_Free [COMPOBJ.505] */ @@ -137,6 +124,26 @@ VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,SEGPTR pv) HeapFree( GetProcessHeap(), 0, ptr ); } +/****************************************************************************** + * IMalloc16_Realloc [COMPOBJ.504] + */ +SEGPTR WINAPI IMalloc16_fnRealloc(IMalloc16* iface,SEGPTR pv,DWORD cb) +{ + SEGPTR ret; + ICOM_THIS(IMalloc16Impl,iface); + TRACE("(%p)->Realloc(%08lx,%ld)\n",This,pv,cb); + if (!pv) + ret = IMalloc16_fnAlloc(iface, cb); + else if (cb) { + ret = MapLS( HeapReAlloc( GetProcessHeap(), 0, MapSL(pv), cb ) ); + UnMapLS(pv); + } else { + IMalloc16_fnFree(iface, pv); + ret = 0; + } + return ret; +} + /****************************************************************************** * IMalloc16_GetSize [COMPOBJ.506] */