mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[SHLWAPI] Use malloc/free instead of HeapAlloc/HeapFree
This is what wine does. To avoid a dependency on msvcrt, link crtheap library, that provides simple wrappers around HeapAlloc, etc.
This commit is contained in:
@@ -67,7 +67,7 @@ target_compile_options(shlwapi_autocomp PRIVATE $<TARGET_PROPERTY:shlwapi,COMPIL
|
||||
add_dependencies(shlwapi_autocomp psdk)
|
||||
|
||||
set_module_type(shlwapi win32dll UNICODE)
|
||||
target_link_libraries(shlwapi uuid wine cppstl)
|
||||
target_link_libraries(shlwapi uuid wine crtheap cppstl)
|
||||
add_delay_importlibs(shlwapi userenv oleaut32 ole32 comctl32 comdlg32 mpr mlang urlmon shell32 winmm version)
|
||||
add_importlibs(shlwapi user32 gdi32 advapi32 wininet msvcrt kernel32 ntdll)
|
||||
#add_pch(shlwapi precomp.h "${PCH_SKIP_SOURCE}")
|
||||
|
||||
+10
-13
@@ -62,8 +62,7 @@ static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen,
|
||||
else
|
||||
{
|
||||
/* Create a new buffer big enough for the string */
|
||||
*lpszOut = HeapAlloc(GetProcessHeap(), 0,
|
||||
dwStrLen * sizeof(WCHAR));
|
||||
*lpszOut = malloc(dwStrLen * sizeof(WCHAR));
|
||||
if (!*lpszOut)
|
||||
return FALSE;
|
||||
}
|
||||
@@ -421,10 +420,10 @@ HRESULT WINAPI AssocQueryKeyA(ASSOCF cfFlags, ASSOCKEY assockey, LPCSTR pszAssoc
|
||||
}
|
||||
|
||||
if (lpszAssocW != szAssocW)
|
||||
HeapFree(GetProcessHeap(), 0, lpszAssocW);
|
||||
free(lpszAssocW);
|
||||
|
||||
if (lpszExtraW != szExtraW)
|
||||
HeapFree(GetProcessHeap(), 0, lpszExtraW);
|
||||
free(lpszExtraW);
|
||||
|
||||
return hRet;
|
||||
}
|
||||
@@ -496,8 +495,7 @@ HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc,
|
||||
DWORD dwLenOut = *pcchOut;
|
||||
|
||||
if (dwLenOut >= MAX_PATH)
|
||||
lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
|
||||
(dwLenOut + 1) * sizeof(WCHAR));
|
||||
lpszReturnW = malloc((dwLenOut + 1) * sizeof(WCHAR));
|
||||
else
|
||||
dwLenOut = ARRAY_SIZE(szReturnW);
|
||||
|
||||
@@ -514,14 +512,14 @@ HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc,
|
||||
|
||||
*pcchOut = dwLenOut;
|
||||
if (lpszReturnW != szReturnW)
|
||||
HeapFree(GetProcessHeap(), 0, lpszReturnW);
|
||||
free(lpszReturnW);
|
||||
}
|
||||
}
|
||||
|
||||
if (lpszAssocW != szAssocW)
|
||||
HeapFree(GetProcessHeap(), 0, lpszAssocW);
|
||||
free(lpszAssocW);
|
||||
if (lpszExtraW != szExtraW)
|
||||
HeapFree(GetProcessHeap(), 0, lpszExtraW);
|
||||
free(lpszExtraW);
|
||||
return hRet;
|
||||
}
|
||||
|
||||
@@ -592,8 +590,7 @@ HRESULT WINAPI AssocQueryStringByKeyA(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc
|
||||
{
|
||||
DWORD dwLenOut = *pcchOut;
|
||||
if (dwLenOut >= MAX_PATH)
|
||||
lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
|
||||
(dwLenOut + 1) * sizeof(WCHAR));
|
||||
lpszReturnW = malloc((dwLenOut + 1) * sizeof(WCHAR));
|
||||
|
||||
if (lpszReturnW)
|
||||
{
|
||||
@@ -605,12 +602,12 @@ HRESULT WINAPI AssocQueryStringByKeyA(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc
|
||||
*pcchOut = dwLenOut;
|
||||
|
||||
if (lpszReturnW != szReturnW)
|
||||
HeapFree(GetProcessHeap(), 0, lpszReturnW);
|
||||
free(lpszReturnW);
|
||||
}
|
||||
}
|
||||
|
||||
if (lpszExtraW != szExtraW)
|
||||
HeapFree(GetProcessHeap(), 0, lpszExtraW);
|
||||
free(lpszExtraW);
|
||||
return hRet;
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ INT_PTR WINAPI SHMessageBoxCheckA(HWND hWnd, LPCSTR lpszText, LPCSTR lpszTitle,
|
||||
if (lpszText)
|
||||
{
|
||||
iLen = MultiByteToWideChar(CP_ACP, 0, lpszText, -1, NULL, 0);
|
||||
szTextBuff = HeapAlloc(GetProcessHeap(), 0, iLen * sizeof(WCHAR));
|
||||
szTextBuff = malloc(iLen * sizeof(WCHAR));
|
||||
MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTextBuff, iLen);
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ INT_PTR WINAPI SHMessageBoxCheckA(HWND hWnd, LPCSTR lpszText, LPCSTR lpszTitle,
|
||||
|
||||
iRetVal = SHMessageBoxCheckW(hWnd, szTextBuff, lpszTitle ? szTitleBuff : NULL,
|
||||
dwType, iRet, szIdBuff);
|
||||
HeapFree(GetProcessHeap(), 0, szTextBuff);
|
||||
free(szTextBuff);
|
||||
return iRetVal;
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -398,7 +398,7 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
|
||||
dwNumValues = dwCount;
|
||||
|
||||
/* Note: dwCount = number of items + 1; The extra item is the end node */
|
||||
format = formatList = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(FORMATETC));
|
||||
format = formatList = malloc(dwCount * sizeof(FORMATETC));
|
||||
if (!formatList)
|
||||
{
|
||||
RegCloseKey(hDocs);
|
||||
@@ -422,7 +422,7 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
|
||||
(PBYTE)szValueBuff, &dwValueSize);
|
||||
if (!dwRet)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, formatList);
|
||||
free(formatList);
|
||||
RegCloseKey(hDocs);
|
||||
hr = E_FAIL;
|
||||
goto exit;
|
||||
@@ -450,7 +450,7 @@ HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
|
||||
|
||||
/* Create a clipboard enumerator */
|
||||
hr = CreateFormatEnumerator(dwNumValues, formatList, &pIEnumFormatEtc);
|
||||
HeapFree(GetProcessHeap(), 0, formatList);
|
||||
free(formatList);
|
||||
if (FAILED(hr)) goto exit;
|
||||
|
||||
/* Set our enumerator as the browsers property */
|
||||
@@ -2433,7 +2433,7 @@ BOOL WINAPI FDSA_Destroy(FDSA_info *info)
|
||||
|
||||
if(info->flags & FDSA_FLAG_INTERNAL_ALLOC)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, info->mem);
|
||||
free(info->mem);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -2455,11 +2455,11 @@ DWORD WINAPI FDSA_InsertItem(FDSA_info *info, DWORD where, const void *block)
|
||||
{
|
||||
DWORD size = (info->blocks_alloced + info->inc) * info->block_size;
|
||||
if(info->flags & 0x1)
|
||||
info->mem = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->mem, size);
|
||||
info->mem = _recalloc(info->mem, 1, size);
|
||||
else
|
||||
{
|
||||
void *old_mem = info->mem;
|
||||
info->mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
||||
info->mem = calloc(1, size);
|
||||
memcpy(info->mem, old_mem, info->blocks_alloced * info->block_size);
|
||||
}
|
||||
info->blocks_alloced += info->inc;
|
||||
@@ -4929,7 +4929,7 @@ HKEY WINAPI SHGetShellKey(DWORD flags, LPCWSTR sub_key, BOOL create)
|
||||
else
|
||||
size_user = 0;
|
||||
|
||||
path = HeapAlloc(GetProcessHeap(), 0, size_key+size_subkey+size_user+sizeof(WCHAR));
|
||||
path = malloc(size_key + size_subkey + size_user + sizeof(WCHAR));
|
||||
if(!path) {
|
||||
ERR("Out of memory\n");
|
||||
return NULL;
|
||||
@@ -4949,7 +4949,7 @@ HKEY WINAPI SHGetShellKey(DWORD flags, LPCWSTR sub_key, BOOL create)
|
||||
RegOpenKeyExW((flags&0xf)==SHKEY_Root_HKLM?HKEY_LOCAL_MACHINE:HKEY_CURRENT_USER,
|
||||
path, 0, MAXIMUM_ALLOWED, &hkey);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, path);
|
||||
free(path);
|
||||
return hkey;
|
||||
}
|
||||
|
||||
@@ -5197,7 +5197,7 @@ INT WINAPIV ShellMessageBoxWrapW(HINSTANCE hInstance, HWND hWnd, LPCWSTR lpText,
|
||||
|
||||
if (len)
|
||||
{
|
||||
szText = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
||||
szText = malloc((len + 1) * sizeof(WCHAR));
|
||||
if (szText) LoadStringW(hInstance, LOWORD(lpText), szText, len + 1);
|
||||
}
|
||||
pszText = szText;
|
||||
@@ -5220,7 +5220,7 @@ INT WINAPIV ShellMessageBoxWrapW(HINSTANCE hInstance, HWND hWnd, LPCWSTR lpText,
|
||||
#endif
|
||||
ret = MessageBoxW(hWnd, pszTemp, pszTitle, uType);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, szText);
|
||||
free(szText);
|
||||
LocalFree(pszTemp);
|
||||
return ret;
|
||||
}
|
||||
@@ -5288,7 +5288,7 @@ PSECURITY_DESCRIPTOR WINAPI GetShellSecurityDescriptor(const PSHELL_USER_PERMISS
|
||||
if (apUserPerm == NULL || cUserPerm <= 0)
|
||||
return NULL;
|
||||
|
||||
sidlist = HeapAlloc(GetProcessHeap(), 0, cUserPerm * sizeof(PSID));
|
||||
sidlist = malloc(cUserPerm * sizeof(PSID));
|
||||
if (!sidlist)
|
||||
return NULL;
|
||||
|
||||
@@ -5385,7 +5385,7 @@ free_sids:
|
||||
if (!cur_user || sidlist[i] != cur_user)
|
||||
FreeSid(sidlist[i]);
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, sidlist);
|
||||
free(sidlist);
|
||||
|
||||
return psd;
|
||||
}
|
||||
@@ -5537,13 +5537,13 @@ INT WINAPI SHFormatDateTimeA(const FILETIME UNALIGNED *fileTime, DWORD *flags,
|
||||
if (!buf || !size)
|
||||
return 0;
|
||||
|
||||
bufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
|
||||
bufW = malloc(sizeof(WCHAR) * size);
|
||||
retval = SHFormatDateTimeW(fileTime, flags, bufW, size);
|
||||
|
||||
if (retval != 0)
|
||||
retval = WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, size, NULL, NULL);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, bufW);
|
||||
free(bufW);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@@ -1259,7 +1259,7 @@ static BOOL SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile, DWORD dwWhich)
|
||||
/* Try dirs listed in %PATH% */
|
||||
dwLenPATH = GetEnvironmentVariableW(szPath, buff, MAX_PATH);
|
||||
|
||||
if (!dwLenPATH || !(lpszPATH = HeapAlloc(GetProcessHeap(), 0, (dwLenPATH + 1) * sizeof (WCHAR))))
|
||||
if (!dwLenPATH || !(lpszPATH = malloc((dwLenPATH + 1) * sizeof (WCHAR))))
|
||||
return FALSE;
|
||||
|
||||
GetEnvironmentVariableW(szPath, lpszPATH, dwLenPATH + 1);
|
||||
@@ -1282,17 +1282,17 @@ static BOOL SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile, DWORD dwWhich)
|
||||
|
||||
if (!PathAppendW(buff, lpszFile))
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
||||
free(lpszPATH);
|
||||
return FALSE;
|
||||
}
|
||||
if (PathFileExistsDefExtW(buff, dwWhich))
|
||||
{
|
||||
lstrcpyW(lpszFile, buff);
|
||||
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
||||
free(lpszPATH);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
||||
free(lpszPATH);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb
|
||||
|
||||
if (newLen > This->dwLength)
|
||||
{
|
||||
LPBYTE newBuf = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pbBuffer, newLen);
|
||||
BYTE *newBuf = _recalloc(This->pbBuffer, 1, newLen);
|
||||
if (!newBuf)
|
||||
return STG_E_INSUFFICIENTMEMORY;
|
||||
|
||||
@@ -244,7 +244,7 @@ static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewS
|
||||
|
||||
/* we cut off the high part here */
|
||||
newLen = libNewSize.u.LowPart;
|
||||
newBuf = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pbBuffer, newLen);
|
||||
newBuf = _recalloc(This->pbBuffer, 1, newLen);
|
||||
if (!newBuf)
|
||||
return STG_E_INSUFFICIENTMEMORY;
|
||||
|
||||
@@ -442,7 +442,7 @@ static ISHRegStream *IStream_Create(HKEY hKey, LPBYTE pbBuffer, DWORD dwLength)
|
||||
{
|
||||
ISHRegStream* regStream;
|
||||
|
||||
regStream = HeapAlloc(GetProcessHeap(), 0, sizeof(ISHRegStream));
|
||||
regStream = malloc(sizeof(ISHRegStream));
|
||||
|
||||
if (regStream)
|
||||
{
|
||||
|
||||
@@ -1792,13 +1792,13 @@ static HRESULT _SHStrDupAToBSTR(LPCSTR src, BSTR *pBstrOut)
|
||||
if (src)
|
||||
{
|
||||
INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
|
||||
WCHAR* szTemp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||
WCHAR *szTemp = malloc(len * sizeof(WCHAR));
|
||||
|
||||
if (szTemp)
|
||||
{
|
||||
MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
|
||||
*pBstrOut = SysAllocString(szTemp);
|
||||
HeapFree(GetProcessHeap(), 0, szTemp);
|
||||
free(szTemp);
|
||||
|
||||
if (*pBstrOut)
|
||||
return S_OK;
|
||||
@@ -2895,7 +2895,7 @@ DWORD WINAPI SHUnicodeToAnsiCP(UINT CodePage, LPCWSTR lpSrcStr, LPSTR lpDstStr,
|
||||
lenW = len;
|
||||
hr = ConvertINetUnicodeToMultiByte(&dwMode, CodePage, lpSrcStr, &lenW, NULL, &needed);
|
||||
needed++;
|
||||
mem = HeapAlloc(GetProcessHeap(), 0, needed);
|
||||
mem = malloc(needed);
|
||||
if (!mem)
|
||||
return 0;
|
||||
|
||||
@@ -2905,7 +2905,7 @@ DWORD WINAPI SHUnicodeToAnsiCP(UINT CodePage, LPCWSTR lpSrcStr, LPSTR lpDstStr,
|
||||
reqLen = SHTruncateString(mem, dstlen);
|
||||
if (reqLen > 0) memcpy(lpDstStr, mem, reqLen-1);
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, mem);
|
||||
free(mem);
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
@@ -2920,7 +2920,7 @@ DWORD WINAPI SHUnicodeToAnsiCP(UINT CodePage, LPCWSTR lpSrcStr, LPSTR lpDstStr,
|
||||
reqLen = WideCharToMultiByte(CodePage, 0, lpSrcStr, len, NULL, 0, NULL, NULL);
|
||||
if (reqLen)
|
||||
{
|
||||
mem = HeapAlloc(GetProcessHeap(), 0, reqLen);
|
||||
mem = malloc(reqLen);
|
||||
if (mem)
|
||||
{
|
||||
WideCharToMultiByte(CodePage, 0, lpSrcStr, len, mem, reqLen, NULL, NULL);
|
||||
@@ -2929,7 +2929,7 @@ DWORD WINAPI SHUnicodeToAnsiCP(UINT CodePage, LPCWSTR lpSrcStr, LPSTR lpDstStr,
|
||||
reqLen++;
|
||||
|
||||
lstrcpynA(lpDstStr, mem, reqLen);
|
||||
HeapFree(GetProcessHeap(), 0, mem);
|
||||
free(mem);
|
||||
lpDstStr[reqLen-1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user