From 921df719e5b5a534f23359bbcf1dcb7248f5efc3 Mon Sep 17 00:00:00 2001 From: "Dimitrie O. Paun" Date: Sat, 11 Oct 2003 05:25:31 +0000 Subject: [PATCH] Fix some instances of memory allocation through HeapReAlloc(). --- dlls/dmusic/dmusic.c | 3 ++- programs/winedbg/hash.c | 4 +++- programs/winhelp/macro.c | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c index e279d5cdac3..db3a8976c03 100644 --- a/dlls/dmusic/dmusic.c +++ b/dlls/dmusic/dmusic.c @@ -133,7 +133,8 @@ HRESULT WINAPI IDirectMusic8Impl_CreatePort (LPDIRECTMUSIC8 iface, REFCLSID rcls TRACE("(%p, %s, %p, %p, %p)\n", This, debugstr_guid(rclsidPort), pPortParams, ppPort, pUnkOuter); for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) { if (IsEqualCLSID (rclsidPort, &PortCaps.guidPort)) { - This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports); + if(!This->ppPorts) This->ppPorts = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIRECTMUSICPORT) * This->nrofports); + else This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports); if (NULL == This->ppPorts[This->nrofports]) { *ppPort = (LPDIRECTMUSICPORT)NULL; return E_OUTOFMEMORY; diff --git a/programs/winedbg/hash.c b/programs/winedbg/hash.c index 71105244ea1..a37a4d6dab1 100644 --- a/programs/winedbg/hash.c +++ b/programs/winedbg/hash.c @@ -1339,7 +1339,9 @@ void DEBUG_InfoSymbols(const char* str) { if (num_used_array == num_alloc_array) { - array = HeapReAlloc(GetProcessHeap(), 0, array, sizeof(*array) * (num_alloc_array += 32)); + int size = sizeof(*array) * (num_alloc_array += 32); + if (!array) array = HeapAlloc(GetProcessHeap(), 0, size); + else array = HeapReAlloc(GetProcessHeap(), 0, array, size); if (!array) return; } array[num_used_array++] = nh; diff --git a/programs/winhelp/macro.c b/programs/winhelp/macro.c index 4a8d0915f58..8b39fb2429b 100644 --- a/programs/winhelp/macro.c +++ b/programs/winhelp/macro.c @@ -832,6 +832,7 @@ void MACRO_RegisterRoutine(LPCSTR dll, LPCSTR proc, LPCSTR args) { HANDLE hLib; void (*fn)(); + int size; WINE_TRACE("(\"%s\", \"%s\", \"%s\")\n", dll, proc, args); @@ -849,9 +850,9 @@ void MACRO_RegisterRoutine(LPCSTR dll, LPCSTR proc, LPCSTR args) } /* FIXME: the library will not be unloaded until exit of program */ - - MACRO_Loaded = HeapReAlloc(GetProcessHeap(), 0, MACRO_Loaded, - ++MACRO_NumLoaded * sizeof(struct MacroDesc)); + size = ++MACRO_NumLoaded * sizeof(struct MacroDesc); + if (!MACRO_Loaded) MACRO_Loaded = HeapAlloc(GetProcessHeap(), 0, size); + else MACRO_Loaded = HeapReAlloc(GetProcessHeap(), 0, MACRO_Loaded, size); MACRO_Loaded[MACRO_NumLoaded - 1].name = strdup(proc); /* FIXME */ MACRO_Loaded[MACRO_NumLoaded - 1].alias = NULL; MACRO_Loaded[MACRO_NumLoaded - 1].isBool = 0;