wusa: Use CRT allocation functions.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2022-03-01 11:42:59 +01:00 committed by Alexandre Julliard
parent d86c22ee28
commit f0f125f5c5
3 changed files with 66 additions and 93 deletions

View File

@ -54,12 +54,12 @@ struct installer_state
static void * CDECL cabinet_alloc(ULONG cb)
{
return heap_alloc(cb);
return malloc(cb);
}
static void CDECL cabinet_free(void *pv)
{
heap_free(pv);
free(pv);
}
static INT_PTR CDECL cabinet_open(char *pszFile, int oflag, int pmode)
@ -134,7 +134,7 @@ static WCHAR *path_combine(const WCHAR *path, const WCHAR *filename)
if (!path || !filename) return NULL;
length = lstrlenW(path) + lstrlenW(filename) + 2;
if (!(result = heap_alloc(length * sizeof(WCHAR)))) return NULL;
if (!(result = malloc(length * sizeof(WCHAR)))) return NULL;
lstrcpyW(result, path);
if (result[0] && result[lstrlenW(result) - 1] != '\\') lstrcatW(result, L"\\");
@ -146,7 +146,7 @@ static WCHAR *get_uncompressed_path(PFDINOTIFICATION pfdin)
{
WCHAR *file = strdupAtoW(pfdin->psz1);
WCHAR *path = path_combine(pfdin->pv, file);
heap_free(file);
free(file);
return path;
}
@ -187,7 +187,7 @@ static BOOL create_parent_directory(const WCHAR *filename)
ret = create_directory(path);
done:
heap_free(path);
free(path);
return ret;
}
@ -209,7 +209,7 @@ static INT_PTR cabinet_copy_file(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfd
handle = CreateFileW(file, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
}
heap_free(file);
free(file);
return (handle != INVALID_HANDLE_VALUE) ? (INT_PTR)handle : -1;
}
@ -257,7 +257,7 @@ static BOOL extract_cabinet(const WCHAR *filename, const WCHAR *destination)
if ((filenameA = strdupWtoA(filename)))
{
ret = FDICopy(hfdi, filenameA, NULL, 0, cabinet_notify, NULL, (void *)destination);
heap_free(filenameA);
free(filenameA);
}
FDIDestroy(hfdi);
@ -271,18 +271,18 @@ static const WCHAR *create_temp_directory(struct installer_state *state)
WCHAR tmp[MAX_PATH];
if (!GetTempPathW(ARRAY_SIZE(tmp), tmp)) return NULL;
if (!(entry = heap_alloc(sizeof(*entry)))) return NULL;
if (!(entry->path = heap_alloc((MAX_PATH + 20) * sizeof(WCHAR))))
if (!(entry = malloc(sizeof(*entry)))) return NULL;
if (!(entry->path = malloc((MAX_PATH + 20) * sizeof(WCHAR))))
{
heap_free(entry);
free(entry);
return NULL;
}
for (;;)
{
if (!GetTempFileNameW(tmp, L"msu", ++id, entry->path))
{
heap_free(entry->path);
heap_free(entry);
free(entry->path);
free(entry);
return NULL;
}
if (CreateDirectoryW(entry->path, NULL)) break;
@ -300,7 +300,7 @@ static BOOL delete_directory(const WCHAR *path)
if (!(full_path = path_combine(path, L"*"))) return FALSE;
search = FindFirstFileW(full_path, &data);
heap_free(full_path);
free(full_path);
if (search != INVALID_HANDLE_VALUE)
{
@ -313,7 +313,7 @@ static BOOL delete_directory(const WCHAR *path)
delete_directory(full_path);
else
DeleteFileW(full_path);
heap_free(full_path);
free(full_path);
}
while (FindNextFileW(search, &data));
FindClose(search);
@ -332,8 +332,8 @@ static void installer_cleanup(struct installer_state *state)
{
list_remove(&tempdir->entry);
delete_directory(tempdir->path);
heap_free(tempdir->path);
heap_free(tempdir);
free(tempdir->path);
free(tempdir);
}
LIST_FOR_EACH_ENTRY_SAFE(assembly, assembly2, &state->assemblies, struct assembly_entry, entry)
{
@ -377,11 +377,11 @@ static BOOL load_assemblies_from_cab(const WCHAR *filename, struct installer_sta
FIXME("Cabinet uses proprietary msdelta file compression which is not (yet) supported\n");
FIXME("Installation of msu file will most likely fail\n");
}
heap_free(path);
free(path);
if (!(path = path_combine(temp_path, L"*"))) return FALSE;
search = FindFirstFileW(path, &data);
heap_free(path);
free(path);
if (search != INVALID_HANDLE_VALUE)
{
@ -393,7 +393,7 @@ static BOOL load_assemblies_from_cab(const WCHAR *filename, struct installer_sta
if (!(path = path_combine(temp_path, data.cFileName))) continue;
if ((assembly = load_manifest(path)))
list_add_tail(&state->assemblies, &assembly->entry);
heap_free(path);
free(path);
}
while (FindNextFileW(search, &data));
FindClose(search);
@ -439,13 +439,13 @@ static BOOL strbuf_init(struct strbuf *buf)
{
buf->pos = 0;
buf->len = 64;
buf->buf = heap_alloc(buf->len * sizeof(WCHAR));
buf->buf = malloc(buf->len * sizeof(WCHAR));
return buf->buf != NULL;
}
static void strbuf_free(struct strbuf *buf)
{
heap_free(buf->buf);
free(buf->buf);
buf->buf = NULL;
}
@ -461,7 +461,7 @@ static BOOL strbuf_append(struct strbuf *buf, const WCHAR *str, DWORD len)
if (buf->pos + len + 1 > buf->len)
{
new_len = max(buf->pos + len + 1, buf->len * 2);
new_buf = heap_realloc(buf->buf, new_len * sizeof(WCHAR));
new_buf = realloc(buf->buf, new_len * sizeof(WCHAR));
if (!new_buf)
{
strbuf_free(buf);
@ -548,10 +548,10 @@ static WCHAR *expand_expression(struct assembly_entry *assembly, const WCHAR *ex
if (!(key = strdupWn(pos, next - pos))) goto error;
value = lookup_expression(assembly, key);
heap_free(key);
free(key);
if (!value) goto error;
strbuf_append(&buf, value, ~0U);
heap_free(value);
free(value);
}
strbuf_append(&buf, pos, ~0U);
@ -597,9 +597,9 @@ static BOOL install_files_copy(struct assembly_entry *assembly, const WCHAR *sou
}
error:
heap_free(target_path);
heap_free(target);
heap_free(source);
free(target_path);
free(target);
free(source);
return ret;
}
@ -620,7 +620,7 @@ static BOOL install_files(struct assembly_entry *assembly, BOOL dryrun)
if (!(ret = install_files_copy(assembly, source_path, fileop, dryrun))) break;
}
heap_free(source_path);
free(source_path);
return ret;
}
@ -667,7 +667,7 @@ static BOOL install_registry_string(struct assembly_entry *assembly, HKEY key, s
ret = FALSE;
}
heap_free(value);
free(value);
return ret;
}
@ -725,7 +725,7 @@ static BOOL install_registry_multisz(struct assembly_entry *assembly, HKEY key,
ret = FALSE;
}
heap_free(value);
free(value);
return ret;
}
@ -755,7 +755,7 @@ static BYTE *parse_hex(const WCHAR *input, DWORD *size)
if (length & 1) return NULL;
length >>= 1;
if (!(output = heap_alloc(length))) return NULL;
if (!(output = malloc(length))) return NULL;
for (p = output; *input; input += 2)
{
number[0] = input[0];
@ -781,7 +781,7 @@ static BOOL install_registry_binary(struct assembly_entry *assembly, HKEY key, s
ret = FALSE;
}
heap_free(value);
free(value);
return ret;
}
@ -954,7 +954,7 @@ static BOOL install_msu(const WCHAR *filename, struct installer_state *state)
/* load all manifests from contained cabinet archives */
if (!(path = path_combine(temp_path, L"*.cab"))) goto done;
search = FindFirstFileW(path, &data);
heap_free(path);
free(path);
if (search != INVALID_HANDLE_VALUE)
{
@ -965,7 +965,7 @@ static BOOL install_msu(const WCHAR *filename, struct installer_state *state)
if (!(path = path_combine(temp_path, data.cFileName))) continue;
if (!load_assemblies_from_cab(path, state))
ERR("Failed to load all manifests from %s, ignoring\n", debugstr_w(path));
heap_free(path);
free(path);
}
while (FindNextFileW(search, &data));
FindClose(search);
@ -974,7 +974,7 @@ static BOOL install_msu(const WCHAR *filename, struct installer_state *state)
/* load all update descriptions */
if (!(path = path_combine(temp_path, L"*.xml"))) goto done;
search = FindFirstFileW(path, &data);
heap_free(path);
free(path);
if (search != INVALID_HANDLE_VALUE)
{
@ -984,7 +984,7 @@ static BOOL install_msu(const WCHAR *filename, struct installer_state *state)
if (!(path = path_combine(temp_path, data.cFileName))) continue;
if (!load_update(path, &state->updates))
ERR("Failed to load all updates from %s, ignoring\n", debugstr_w(path));
heap_free(path);
free(path);
}
while (FindNextFileW(search, &data));
FindClose(search);

View File

@ -32,28 +32,28 @@ WINE_DEFAULT_DEBUG_CHANNEL(wusa);
static struct dependency_entry *alloc_dependency(void)
{
struct dependency_entry *entry = heap_alloc_zero(sizeof(*entry));
struct dependency_entry *entry = calloc(1, sizeof(*entry));
if (!entry) ERR("Failed to allocate memory for dependency\n");
return entry;
}
static struct fileop_entry *alloc_fileop(void)
{
struct fileop_entry *entry = heap_alloc_zero(sizeof(*entry));
struct fileop_entry *entry = calloc(1, sizeof(*entry));
if (!entry) ERR("Failed to allocate memory for fileop\n");
return entry;
}
static struct registrykv_entry *alloc_registrykv(void)
{
struct registrykv_entry *entry = heap_alloc_zero(sizeof(*entry));
struct registrykv_entry *entry = calloc(1, sizeof(*entry));
if (!entry) ERR("Failed to allocate memory for registrykv\n");
return entry;
}
static struct registryop_entry *alloc_registryop(void)
{
struct registryop_entry *entry = heap_alloc_zero(sizeof(*entry));
struct registryop_entry *entry = calloc(1, sizeof(*entry));
if (!entry) ERR("Failed to allocate memory for registryop\n");
else
{
@ -64,7 +64,7 @@ static struct registryop_entry *alloc_registryop(void)
static struct assembly_entry *alloc_assembly(void)
{
struct assembly_entry *entry = heap_alloc_zero(sizeof(*entry));
struct assembly_entry *entry = calloc(1, sizeof(*entry));
if (!entry) ERR("Failed to allocate memory for assembly\n");
else
{
@ -77,39 +77,39 @@ static struct assembly_entry *alloc_assembly(void)
static void clear_identity(struct assembly_identity *entry)
{
heap_free(entry->name);
heap_free(entry->version);
heap_free(entry->architecture);
heap_free(entry->language);
heap_free(entry->pubkey_token);
free(entry->name);
free(entry->version);
free(entry->architecture);
free(entry->language);
free(entry->pubkey_token);
}
void free_dependency(struct dependency_entry *entry)
{
clear_identity(&entry->identity);
heap_free(entry);
free(entry);
}
static void free_fileop(struct fileop_entry *entry)
{
heap_free(entry->source);
heap_free(entry->target);
heap_free(entry);
free(entry->source);
free(entry->target);
free(entry);
}
static void free_registrykv(struct registrykv_entry *entry)
{
heap_free(entry->name);
heap_free(entry->value_type);
heap_free(entry->value);
heap_free(entry);
free(entry->name);
free(entry->value_type);
free(entry->value);
free(entry);
}
static void free_registryop(struct registryop_entry *entry)
{
struct registrykv_entry *keyvalue, *keyvalue2;
heap_free(entry->key);
free(entry->key);
LIST_FOR_EACH_ENTRY_SAFE(keyvalue, keyvalue2, &entry->keyvalues, struct registrykv_entry, entry)
{
@ -117,7 +117,7 @@ static void free_registryop(struct registryop_entry *entry)
free_registrykv(keyvalue);
}
heap_free(entry);
free(entry);
}
void free_assembly(struct assembly_entry *entry)
@ -126,8 +126,8 @@ void free_assembly(struct assembly_entry *entry)
struct fileop_entry *fileop, *fileop2;
struct registryop_entry *registryop, *registryop2;
heap_free(entry->filename);
heap_free(entry->displayname);
free(entry->filename);
free(entry->displayname);
clear_identity(&entry->identity);
LIST_FOR_EACH_ENTRY_SAFE(dependency, dependency2, &entry->dependencies, struct dependency_entry, entry)
@ -146,7 +146,7 @@ void free_assembly(struct assembly_entry *entry)
free_registryop(registryop);
}
heap_free(entry);
free(entry);
}
static WCHAR *get_xml_attribute(IXMLDOMElement *root, const WCHAR *name)
@ -304,7 +304,7 @@ static BOOL read_dependent_assembly(IXMLDOMElement *root, struct assembly_identi
error:
if (child) IXMLDOMElement_Release(child);
heap_free(dependency_type);
free(dependency_type);
return ret;
}
@ -498,7 +498,7 @@ static BOOL read_registry_keys(IXMLDOMElement *child, WCHAR *tagname, void *cont
free_registryop(entry);
}
heap_free(keyname);
free(keyname);
return FALSE;
}
@ -622,7 +622,7 @@ static BOOL read_servicing(IXMLDOMElement *child, WCHAR *tagname, void *context)
else
FIXME("action %s not supported\n", debugstr_w(action));
heap_free(action);
free(action);
return ret;
}

View File

@ -78,29 +78,6 @@ void free_dependency(struct dependency_entry *entry) DECLSPEC_HIDDEN;
struct assembly_entry *load_manifest(const WCHAR *filename) DECLSPEC_HIDDEN;
BOOL load_update(const WCHAR *filename, struct list *update_list) DECLSPEC_HIDDEN;
static void *heap_alloc(size_t len) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc(size_t len)
{
return HeapAlloc(GetProcessHeap(), 0, len);
}
static void *heap_alloc_zero(size_t len) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc_zero(size_t len)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
}
static void *heap_realloc(void *mem, size_t len) __WINE_ALLOC_SIZE(2);
static inline void *heap_realloc(void *mem, size_t len)
{
return HeapReAlloc(GetProcessHeap(), 0, mem, len);
}
static inline BOOL heap_free(void *mem)
{
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline char *strdupWtoA(const WCHAR *str)
{
char *ret = NULL;
@ -108,8 +85,7 @@ static inline char *strdupWtoA(const WCHAR *str)
if (!str) return ret;
len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
if ((ret = heap_alloc(len)))
WideCharToMultiByte(CP_ACP, 0, str, -1, ret, len, NULL, NULL);
if ((ret = malloc(len))) WideCharToMultiByte(CP_ACP, 0, str, -1, ret, len, NULL, NULL);
return ret;
}
@ -120,8 +96,7 @@ static inline WCHAR *strdupAtoW(const char *str)
if (!str) return ret;
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
if ((ret = heap_alloc(len * sizeof(WCHAR))))
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
if ((ret = malloc(len * sizeof(WCHAR)))) MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
return ret;
}
@ -129,8 +104,7 @@ static inline WCHAR *strdupW(const WCHAR *str)
{
WCHAR *ret;
if (!str) return NULL;
ret = heap_alloc((lstrlenW(str) + 1) * sizeof(WCHAR));
if (ret) lstrcpyW(ret, str);
if ((ret = malloc((lstrlenW(str) + 1) * sizeof(WCHAR)))) lstrcpyW(ret, str);
return ret;
}
@ -138,8 +112,7 @@ static inline WCHAR *strdupWn(const WCHAR *str, DWORD len)
{
WCHAR *ret;
if (!str) return NULL;
ret = heap_alloc((len + 1) * sizeof(WCHAR));
if (ret)
if ((ret = malloc((len + 1) * sizeof(WCHAR))))
{
memcpy(ret, str, len * sizeof(WCHAR));
ret[len] = 0;