From 22cf1c9e4de3b5c00358ff2f82282fe1c7ae43a2 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sun, 16 Jul 2006 23:21:36 +0200 Subject: [PATCH] mshtml: Wrap Heap* functions by inline functions. --- dlls/mshtml/main.c | 10 +++++----- dlls/mshtml/mshtml_private.h | 17 +++++++++++++++++ dlls/mshtml/protocol.c | 34 +++++++++++++++++----------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/dlls/mshtml/main.c b/dlls/mshtml/main.c index d4c4bf72675..1bb34de2775 100644 --- a/dlls/mshtml/main.c +++ b/dlls/mshtml/main.c @@ -100,7 +100,7 @@ static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) TRACE("(%p) ref = %lu\n", This, ref); if(!ref) { - HeapFree(GetProcessHeap(), 0, This); + mshtml_free(This); UNLOCK_MODULE(); } @@ -136,7 +136,7 @@ static const IClassFactoryVtbl HTMLClassFactoryVtbl = { static HRESULT ClassFactory_Create(REFIID riid, void **ppv, CreateInstanceFunc fnCreateInstance) { - ClassFactory *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactory)); + ClassFactory *ret = mshtml_alloc(sizeof(ClassFactory)); HRESULT hres; ret->lpVtbl = &HTMLClassFactoryVtbl; @@ -147,7 +147,7 @@ static HRESULT ClassFactory_Create(REFIID riid, void **ppv, CreateInstanceFunc f if(SUCCEEDED(hres)) { LOCK_MODULE(); }else { - HeapFree(GetProcessHeap(), 0, ret); + mshtml_free(ret); *ppv = NULL; } return hres; @@ -314,7 +314,7 @@ static HRESULT register_server(BOOL do_register) INF_SET_ID(LIBID_MSHTML); for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) { - pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39); + pse[i].pszValue = mshtml_alloc(39); sprintf(pse[i].pszValue, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0], clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4], @@ -330,7 +330,7 @@ static HRESULT register_server(BOOL do_register) hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable); for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) - HeapFree(GetProcessHeap(), 0, pse[i].pszValue); + mshtml_free(pse[i].pszValue); return hres; } diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 43f3003482f..254283644f4 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -338,4 +338,21 @@ extern LONG module_ref; #define LOCK_MODULE() InterlockedIncrement(&module_ref) #define UNLOCK_MODULE() InterlockedDecrement(&module_ref) +/* memory allocation functions */ + +static inline void *mshtml_alloc(size_t len) +{ + return HeapAlloc(GetProcessHeap(), 0, len); +} + +static inline void *mshtml_realloc(void *mem, size_t len) +{ + return HeapReAlloc(GetProcessHeap(), 0, mem, len); +} + +static inline BOOL mshtml_free(void *mem) +{ + return HeapFree(GetProcessHeap(), 0, mem); +} + extern HINSTANCE hInst; diff --git a/dlls/mshtml/protocol.c b/dlls/mshtml/protocol.c index 7a9190d3965..6717500c333 100644 --- a/dlls/mshtml/protocol.c +++ b/dlls/mshtml/protocol.c @@ -195,8 +195,8 @@ static ULONG WINAPI AboutProtocol_Release(IInternetProtocol *iface) TRACE("(%p) ref=%lx\n", iface, ref); if(!ref) { - HeapFree(GetProcessHeap(), 0, This->data); - HeapFree(GetProcessHeap(), 0, This); + mshtml_free(This->data); + mshtml_free(This); UNLOCK_MODULE(); } @@ -241,7 +241,7 @@ static HRESULT WINAPI AboutProtocol_Start(IInternetProtocol *iface, LPCWSTR szUr This->data_len = sizeof(html_begin)+sizeof(html_end)-sizeof(WCHAR) + (text ? strlenW(text)*sizeof(WCHAR) : 0); - This->data = HeapAlloc(GetProcessHeap(), 0, This->data_len); + This->data = mshtml_alloc(This->data_len); memcpy(This->data, html_begin, sizeof(html_begin)); if(text) @@ -369,7 +369,7 @@ static HRESULT WINAPI AboutProtocolFactory_CreateInstance(IClassFactory *iface, TRACE("(%p)->(%p %s %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppv); - ret = HeapAlloc(GetProcessHeap(), 0, sizeof(AboutProtocol)); + ret = mshtml_alloc(sizeof(AboutProtocol)); ret->lpInternetProtocolVtbl = &AboutProtocolVtbl; ret->ref = 0; @@ -391,7 +391,7 @@ static HRESULT WINAPI AboutProtocolFactory_CreateInstance(IClassFactory *iface, if(SUCCEEDED(hres)) LOCK_MODULE(); else - HeapFree(GetProcessHeap(), 0, ret); + mshtml_free(ret); return hres; } @@ -540,8 +540,8 @@ static ULONG WINAPI ResProtocol_Release(IInternetProtocol *iface) TRACE("(%p) ref=%lx\n", iface, ref); if(!ref) { - HeapFree(GetProcessHeap(), 0, This->data); - HeapFree(GetProcessHeap(), 0, This); + mshtml_free(This->data); + mshtml_free(This); UNLOCK_MODULE(); } @@ -571,11 +571,11 @@ static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl, ReleaseBindInfo(&bindinfo); len = strlenW(szUrl)+16; - url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); + url = mshtml_alloc(len*sizeof(WCHAR)); hres = CoInternetParseUrl(szUrl, PARSE_ENCODE, 0, url, len, &len, 0); if(FAILED(hres)) { WARN("CoInternetParseUrl failed: %08lx\n", hres); - HeapFree(GetProcessHeap(), 0, url); + mshtml_free(url); IInternetProtocolSink_ReportResult(pOIProtSink, hres, 0, NULL); return hres; } @@ -583,7 +583,7 @@ static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl, if(len < sizeof(wszRes)/sizeof(wszRes[0]) || memcmp(url, wszRes, sizeof(wszRes))) { WARN("Wrong protocol of url: %s\n", debugstr_w(url)); IInternetProtocolSink_ReportResult(pOIProtSink, MK_E_SYNTAX, 0, NULL); - HeapFree(GetProcessHeap(), 0, url); + mshtml_free(url); return MK_E_SYNTAX; } @@ -591,7 +591,7 @@ static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl, if(!(url_file = strchrW(url_dll, '/'))) { WARN("wrong url: %s\n", debugstr_w(url)); IInternetProtocolSink_ReportResult(pOIProtSink, MK_E_SYNTAX, 0, NULL); - HeapFree(GetProcessHeap(), 0, url); + mshtml_free(url); return MK_E_SYNTAX; } @@ -607,24 +607,24 @@ static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl, if(!src) { WARN("Could not find resource\n"); IInternetProtocolSink_ReportResult(pOIProtSink, HRESULT_FROM_WIN32(GetLastError()), 0, NULL); - HeapFree(GetProcessHeap(), 0, url); + mshtml_free(url); return HRESULT_FROM_WIN32(GetLastError()); } if(This->data) { WARN("data already loaded\n"); - HeapFree(GetProcessHeap(), 0, This->data); + mshtml_free(This->data); } This->data_len = SizeofResource(hdll, src); - This->data = HeapAlloc(GetProcessHeap(), 0, This->data_len); + This->data = mshtml_alloc(This->data_len); memcpy(This->data, LoadResource(hdll, src), This->data_len); This->cur = 0; FreeLibrary(hdll); hres = FindMimeFromData(NULL, url_file, NULL, 0, NULL, 0, &mime, 0); - HeapFree(GetProcessHeap(), 0, url); + mshtml_free(url); if(SUCCEEDED(hres)) { IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime); CoTaskMemFree(mime); @@ -752,7 +752,7 @@ static HRESULT WINAPI ResProtocolFactory_CreateInstance(IClassFactory *iface, IU TRACE("(%p)->(%p %s %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppv); - ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ResProtocol)); + ret = mshtml_alloc(sizeof(ResProtocol)); ret->lpInternetProtocolVtbl = &ResProtocolVtbl; ret->ref = 0; ret->data = NULL; @@ -773,7 +773,7 @@ static HRESULT WINAPI ResProtocolFactory_CreateInstance(IClassFactory *iface, IU if(SUCCEEDED(hres)) LOCK_MODULE(); else - HeapFree(GetProcessHeap(), 0, ret); + mshtml_free(ret); return hres; }