Commit 9d6a3845 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

advpack: Use CRT allocation functions.

parent 6129ea6b
......@@ -127,7 +127,7 @@ void set_ldids(HINF hInf, LPCWSTR pszInstallSection, LPCWSTR pszWorkingDir)
if (!(value = wcschr(line, '=')))
{
SetupGetStringFieldW(&context, 0, NULL, 0, &size);
key = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
key = malloc(size * sizeof(WCHAR));
key_copy = key;
SetupGetStringFieldW(&context, 0, key, size, &size);
value = line;
......@@ -165,7 +165,7 @@ void set_ldids(HINF hInf, LPCWSTR pszInstallSection, LPCWSTR pszWorkingDir)
ldid = wcstol(ptr, NULL, 10);
SetupSetDirectoryIdW(hInf, ldid, dest);
}
HeapFree(GetProcessHeap(), 0, key_copy);
free(key_copy);
} while (SetupFindNextLine(&context, &context));
}
......@@ -227,7 +227,7 @@ BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
}
}
pTokenGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
pTokenGroups = malloc(dwSize);
if (!pTokenGroups)
{
CloseHandle(hToken);
......@@ -236,7 +236,7 @@ BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
if (!GetTokenInformation(hToken, TokenGroups, pTokenGroups, dwSize, &dwSize))
{
HeapFree(GetProcessHeap(), 0, pTokenGroups);
free(pTokenGroups);
CloseHandle(hToken);
return FALSE;
}
......@@ -246,7 +246,7 @@ BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
if (!AllocateAndInitializeSid(&SidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSid))
{
HeapFree(GetProcessHeap(), 0, pTokenGroups);
free(pTokenGroups);
return FALSE;
}
......@@ -259,7 +259,7 @@ BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
}
}
HeapFree(GetProcessHeap(), 0, pTokenGroups);
free(pTokenGroups);
FreeSid(pSid);
return bSidFound;
......@@ -469,16 +469,13 @@ HRESULT WINAPI RegisterOCX(HWND hWnd, HINSTANCE hInst, LPCSTR cmdline, INT show)
UNICODE_STRING cmdlineW;
HRESULT hr = E_FAIL;
HMODULE hm = NULL;
DWORD size;
TRACE("(%s)\n", debugstr_a(cmdline));
RtlCreateUnicodeStringFromAsciiz(&cmdlineW, cmdline);
size = (lstrlenW(cmdlineW.Buffer) + 1) * sizeof(WCHAR);
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, size);
cmdline_copy = wcsdup(cmdlineW.Buffer);
cmdline_ptr = cmdline_copy;
lstrcpyW(cmdline_copy, cmdlineW.Buffer);
ocx_filename = get_parameter(&cmdline_ptr, ',', TRUE);
if (!ocx_filename || !*ocx_filename)
......@@ -495,7 +492,7 @@ HRESULT WINAPI RegisterOCX(HWND hWnd, HINSTANCE hInst, LPCSTR cmdline, INT show)
done:
FreeLibrary(hm);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
free(cmdline_copy);
RtlFreeUnicodeString(&cmdlineW);
return hr;
......@@ -636,7 +633,7 @@ HRESULT WINAPI TranslateInfStringA(LPCSTR pszInfFilename, LPCSTR pszInstallSecti
if (res == S_OK)
{
bufferW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
bufferW = malloc(len * sizeof(WCHAR));
res = TranslateInfStringW(filenameW.Buffer, installW.Buffer,
translateW.Buffer, keyW.Buffer, bufferW,
......@@ -654,8 +651,8 @@ HRESULT WINAPI TranslateInfStringA(LPCSTR pszInfFilename, LPCSTR pszInstallSecti
else
res = E_NOT_SUFFICIENT_BUFFER;
}
HeapFree(GetProcessHeap(), 0, bufferW);
free(bufferW);
}
RtlFreeUnicodeString(&filenameW);
......@@ -753,7 +750,7 @@ HRESULT WINAPI TranslateInfStringExA(HINF hInf, LPCSTR pszInfFilename,
if (res == S_OK)
{
bufferW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
bufferW = malloc(len * sizeof(WCHAR));
res = TranslateInfStringExW(hInf, filenameW.Buffer, sectionW.Buffer,
keyW.Buffer, bufferW, len, &len, NULL);
......@@ -771,8 +768,8 @@ HRESULT WINAPI TranslateInfStringExA(HINF hInf, LPCSTR pszInfFilename,
else
res = E_NOT_SUFFICIENT_BUFFER;
}
HeapFree(GetProcessHeap(), 0, bufferW);
free(bufferW);
}
RtlFreeUnicodeString(&filenameW);
......
......@@ -21,21 +21,19 @@
#ifndef __ADVPACK_PRIVATE_H
#define __ADVPACK_PRIVATE_H
#include "wine/heap.h"
HRESULT do_ocx_reg(HMODULE hocx, BOOL do_reg, const WCHAR *flags, const WCHAR *param) DECLSPEC_HIDDEN;
LPWSTR get_parameter(LPWSTR *params, WCHAR separator, BOOL quoted) DECLSPEC_HIDDEN;
void set_ldids(HINF hInf, LPCWSTR pszInstallSection, LPCWSTR pszWorkingDir) DECLSPEC_HIDDEN;
HRESULT launch_exe(LPCWSTR cmd, LPCWSTR dir, HANDLE *phEXE) DECLSPEC_HIDDEN;
static inline char *heap_strdupWtoA(const WCHAR *str)
static inline char *strdupWtoA(const WCHAR *str)
{
char *ret = NULL;
if(str) {
size_t size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
ret = heap_alloc(size);
ret = malloc(size);
if(ret)
WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
}
......
......@@ -46,7 +46,7 @@ static LPWSTR ansi_to_unicode_list(LPCSTR ansi_list)
while (*ptr) ptr += lstrlenA(ptr) + 1;
len = ptr + 1 - ansi_list;
wlen = MultiByteToWideChar(CP_ACP, 0, ansi_list, len, NULL, 0);
list = HeapAlloc(GetProcessHeap(), 0, wlen * sizeof(WCHAR));
list = malloc(wlen * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, ansi_list, len, list, wlen);
return list;
}
......@@ -82,7 +82,7 @@ HRESULT WINAPI AddDelBackupEntryA(LPCSTR lpcszFileList, LPCSTR lpcszBackupDir,
res = AddDelBackupEntryW(filelist, backup, basename.Buffer, dwFlags);
HeapFree(GetProcessHeap(), 0, filelist);
free(filelist);
RtlFreeUnicodeString(&backupdir);
RtlFreeUnicodeString(&basename);
......@@ -246,7 +246,7 @@ HRESULT WINAPI AdvInstallFileW(HWND hwnd, LPCWSTR lpszSourceDir, LPCWSTR lpszSou
LPWSTR szDestFilename;
LPCWSTR szPath;
WCHAR szRootPath[ROOT_LENGTH];
DWORD dwLen, dwLastError;
DWORD dwLastError;
HSPFILEQ fileQueue;
PVOID pContext;
......@@ -268,18 +268,7 @@ HRESULT WINAPI AdvInstallFileW(HWND hwnd, LPCWSTR lpszSourceDir, LPCWSTR lpszSou
szPath = lpszSourceDir + ROOT_LENGTH;
/* use lpszSourceFile as destination filename if lpszDestFile is NULL */
if (lpszDestFile)
{
dwLen = lstrlenW(lpszDestFile);
szDestFilename = HeapAlloc(GetProcessHeap(), 0, (dwLen+1) * sizeof(WCHAR));
lstrcpyW(szDestFilename, lpszDestFile);
}
else
{
dwLen = lstrlenW(lpszSourceFile);
szDestFilename = HeapAlloc(GetProcessHeap(), 0, (dwLen+1) * sizeof(WCHAR));
lstrcpyW(szDestFilename, lpszSourceFile);
}
szDestFilename = wcsdup(lpszDestFile ? lpszDestFile : lpszSourceFile);
/* add the file copy operation to the setup queue */
if (!SetupQueueCopyW(fileQueue, szRootPath, szPath, lpszSourceFile, NULL,
......@@ -313,9 +302,9 @@ HRESULT WINAPI AdvInstallFileW(HWND hwnd, LPCWSTR lpszSourceDir, LPCWSTR lpszSou
done:
SetupTermDefaultQueueCallback(pContext);
SetupCloseFileQueue(fileQueue);
HeapFree(GetProcessHeap(), 0, szDestFilename);
free(szDestFilename);
return HRESULT_FROM_WIN32(dwLastError);
}
......@@ -483,9 +472,8 @@ HRESULT WINAPI DelNodeRunDLL32W(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_w(cmdline), show);
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_copy = wcsdup(cmdline);
cmdline_ptr = cmdline_copy;
lstrcpyW(cmdline_copy, cmdline);
/* get the parameters at indexes 0 and 1 respectively */
szFilename = get_parameter(&cmdline_ptr, ',', TRUE);
......@@ -496,7 +484,7 @@ HRESULT WINAPI DelNodeRunDLL32W(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT
res = DelNodeW(szFilename, dwFlags);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
free(cmdline_copy);
return res;
}
......@@ -549,14 +537,14 @@ static LPSTR convert_file_list(LPCSTR FileList, DWORD *dwNumFiles)
return NULL;
dwLen = last - first + 3; /* room for double-null termination */
szConvertedList = HeapAlloc(GetProcessHeap(), 0, dwLen);
szConvertedList = malloc(dwLen);
lstrcpynA(szConvertedList, first, dwLen - 1);
szConvertedList[dwLen - 1] = '\0';
/* empty list */
if (!szConvertedList[0])
{
HeapFree(GetProcessHeap(), 0, szConvertedList);
free(szConvertedList);
return NULL;
}
......@@ -580,8 +568,8 @@ static LPSTR convert_file_list(LPCSTR FileList, DWORD *dwNumFiles)
static void free_file_node(struct FILELIST *pNode)
{
HeapFree(GetProcessHeap(), 0, pNode->FileName);
HeapFree(GetProcessHeap(), 0, pNode);
free(pNode->FileName);
free(pNode);
}
/* determines whether szFile is in the NULL-separated szFileList */
......@@ -731,7 +719,7 @@ HRESULT WINAPI ExtractFilesA(LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags,
done:
free_file_list(&session);
FreeLibrary(hCabinet);
HeapFree(GetProcessHeap(), 0, szConvertedList);
free(szConvertedList);
return res;
}
......@@ -774,19 +762,19 @@ HRESULT WINAPI ExtractFilesW(LPCWSTR CabName, LPCWSTR ExpandDir, DWORD Flags,
Flags, debugstr_w(FileList), LReserved, Reserved);
if(CabName) {
cab_name = heap_strdupWtoA(CabName);
cab_name = strdupWtoA(CabName);
if(!cab_name)
return E_OUTOFMEMORY;
}
if(ExpandDir) {
expand_dir = heap_strdupWtoA(ExpandDir);
expand_dir = strdupWtoA(ExpandDir);
if(!expand_dir)
hres = E_OUTOFMEMORY;
}
if(SUCCEEDED(hres) && FileList) {
file_list = heap_strdupWtoA(FileList);
file_list = strdupWtoA(FileList);
if(!file_list)
hres = E_OUTOFMEMORY;
}
......@@ -796,9 +784,9 @@ HRESULT WINAPI ExtractFilesW(LPCWSTR CabName, LPCWSTR ExpandDir, DWORD Flags,
if(SUCCEEDED(hres))
hres = ExtractFilesA(cab_name, expand_dir, Flags, file_list, LReserved, Reserved);
heap_free(cab_name);
heap_free(expand_dir);
heap_free(file_list);
free(cab_name);
free(expand_dir);
free(file_list);
return hres;
}
......@@ -1078,7 +1066,7 @@ HRESULT WINAPI GetVersionFromFileExW(LPCWSTR lpszFilename, LPDWORD pdwMSVer,
goto done;
}
pVersionInfo = HeapAlloc(GetProcessHeap(), 0, dwInfoSize);
pVersionInfo = malloc(dwInfoSize);
if (!pVersionInfo)
goto done;
......@@ -1110,7 +1098,7 @@ HRESULT WINAPI GetVersionFromFileExW(LPCWSTR lpszFilename, LPDWORD pdwMSVer,
}
done:
HeapFree(GetProcessHeap(), 0, pVersionInfo);
free(pVersionInfo);
if (bFileCopied)
DeleteFileW(szFile);
......
......@@ -227,13 +227,13 @@ static WCHAR *get_field_string(INFCONTEXT *context, DWORD index, WCHAR *buffer,
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
/* now grow the buffer */
if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, required*sizeof(WCHAR)))) return NULL;
if (buffer != static_buffer) free(buffer);
if (!(buffer = malloc(required*sizeof(WCHAR)))) return NULL;
*size = required;
if (SetupGetStringFieldW(context, index, buffer, *size, &required)) return buffer;
}
if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
if (buffer != static_buffer) free(buffer);
return NULL;
}
......@@ -267,7 +267,7 @@ static HRESULT iterate_section_fields(HINF hinf, PCWSTR section, PCWSTR key,
hr = S_OK;
done:
if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
if (buffer != static_buffer) free(buffer);
return hr;
}
......@@ -401,7 +401,7 @@ static HRESULT get_working_dir(ADVInfo *info, LPCWSTR inf_filename, LPCWSTR work
ptr = path;
}
info->working_dir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
info->working_dir = malloc(len * sizeof(WCHAR));
if (!info->working_dir)
return E_OUTOFMEMORY;
......@@ -421,38 +421,21 @@ static HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec,
if (!(ptr = wcsrchr(inf_filename, '\\')))
ptr = inf_filename;
len = lstrlenW(ptr);
info->inf_filename = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
info->inf_filename = wcsdup(ptr);
if (!info->inf_filename)
return E_OUTOFMEMORY;
lstrcpyW(info->inf_filename, ptr);
/* FIXME: determine the proper platform to install (NTx86, etc) */
if (!install_sec || !*install_sec)
{
len = ARRAY_SIZE(L"DefaultInstall");
ptr = L"DefaultInstall";
}
else
{
len = lstrlenW(install_sec) + 1;
ptr = install_sec;
}
info->install_sec = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
info->install_sec = wcsdup(install_sec && *install_sec ? install_sec : L"DefaultInstall");
if (!info->install_sec)
return E_OUTOFMEMORY;
lstrcpyW(info->install_sec, ptr);
hr = get_working_dir(info, inf_filename, working_dir);
if (FAILED(hr))
return hr;
len = lstrlenW(info->working_dir) + lstrlenW(info->inf_filename) + 2;
info->inf_path = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
info->inf_path = malloc(len * sizeof(WCHAR));
if (!info->inf_path)
return E_OUTOFMEMORY;
......@@ -485,10 +468,10 @@ static void install_release(const ADVInfo *info)
{
SetupCloseInfFile(info->hinf);
HeapFree(GetProcessHeap(), 0, info->inf_path);
HeapFree(GetProcessHeap(), 0, info->inf_filename);
HeapFree(GetProcessHeap(), 0, info->install_sec);
HeapFree(GetProcessHeap(), 0, info->working_dir);
free(info->inf_path);
free(info->inf_filename);
free(info->install_sec);
free(info->working_dir);
}
/* this structure very closely resembles parameters of RunSetupCommand() */
......@@ -733,9 +716,8 @@ INT WINAPI LaunchINFSectionW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT sho
if (!cmdline)
return ADV_FAILURE;
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_copy = wcsdup(cmdline);
cmdline_ptr = cmdline_copy;
lstrcpyW(cmdline_copy, cmdline);
inf_filename = get_parameter(&cmdline_ptr, ',', TRUE);
install_sec = get_parameter(&cmdline_ptr, ',', TRUE);
......@@ -762,7 +744,7 @@ INT WINAPI LaunchINFSectionW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT sho
done:
install_release(&info);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
free(cmdline_copy);
return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
}
......@@ -830,9 +812,8 @@ HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, I
if (!cmdline)
return ADV_FAILURE;
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_copy = wcsdup(cmdline);
cmdline_ptr = cmdline_copy;
lstrcpyW(cmdline_copy, cmdline);
cabinfo.pszInf = get_parameter(&cmdline_ptr, ',', TRUE);
cabinfo.pszSection = get_parameter(&cmdline_ptr, ',', TRUE);
......@@ -845,7 +826,7 @@ HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, I
if (!is_full_path(cabinfo.pszCab) && !is_full_path(cabinfo.pszInf))
{
HeapFree(GetProcessHeap(), 0, cmdline_copy);
free(cmdline_copy);
return E_INVALIDARG;
}
......@@ -862,7 +843,7 @@ HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, I
}
hr = ExecuteCabW(hWnd, &cabinfo, NULL);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
free(cmdline_copy);
return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
}
......
......@@ -95,8 +95,8 @@ static void strentry_atow(const STRENTRYA *aentry, STRENTRYW *wentry)
name_len = MultiByteToWideChar(CP_ACP, 0, aentry->pszName, -1, NULL, 0);
val_len = MultiByteToWideChar(CP_ACP, 0, aentry->pszValue, -1, NULL, 0);
wentry->pszName = HeapAlloc(GetProcessHeap(), 0, name_len * sizeof(WCHAR));
wentry->pszValue = HeapAlloc(GetProcessHeap(), 0, val_len * sizeof(WCHAR));
wentry->pszName = malloc(name_len * sizeof(WCHAR));
wentry->pszValue = malloc(val_len * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, aentry->pszName, -1, wentry->pszName, name_len);
MultiByteToWideChar(CP_ACP, 0, aentry->pszValue, -1, wentry->pszValue, val_len);
......@@ -107,8 +107,8 @@ static STRTABLEW *strtable_atow(const STRTABLEA *atable)
STRTABLEW *wtable;
DWORD j;
wtable = HeapAlloc(GetProcessHeap(), 0, sizeof(STRTABLEW));
wtable->pse = HeapAlloc(GetProcessHeap(), 0, atable->cEntries * sizeof(STRENTRYW));
wtable = malloc(sizeof(STRTABLEW));
wtable->pse = malloc(atable->cEntries * sizeof(STRENTRYW));
wtable->cEntries = atable->cEntries;
for (j = 0; j < wtable->cEntries; j++)
......@@ -123,12 +123,12 @@ static void free_strtable(STRTABLEW *wtable)
for (j = 0; j < wtable->cEntries; j++)
{
HeapFree(GetProcessHeap(), 0, wtable->pse[j].pszName);
HeapFree(GetProcessHeap(), 0, wtable->pse[j].pszValue);
free(wtable->pse[j].pszName);
free(wtable->pse[j].pszValue);
}
HeapFree(GetProcessHeap(), 0, wtable->pse);
HeapFree(GetProcessHeap(), 0, wtable);
free(wtable->pse);
free(wtable);
}
/***********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment