fusion: Use CRT memory allocation functions.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2022-03-30 09:47:46 +03:00 committed by Alexandre Julliard
parent a406123812
commit d3fe9faff0
5 changed files with 64 additions and 80 deletions

View File

@ -62,7 +62,7 @@ static BOOL create_full_path(LPCWSTR path)
BOOL ret = TRUE;
int len;
if (!(new_path = heap_alloc((lstrlenW(path) + 1) * sizeof(WCHAR)))) return FALSE;
if (!(new_path = malloc((lstrlenW(path) + 1) * sizeof(WCHAR)))) return FALSE;
lstrcpyW(new_path, path);
@ -100,7 +100,7 @@ static BOOL create_full_path(LPCWSTR path)
new_path[len] = '\\';
}
heap_free(new_path);
free(new_path);
return ret;
}
@ -197,7 +197,7 @@ static ULONG WINAPI IAssemblyCacheImpl_Release(IAssemblyCache *iface)
if (!refCount)
{
CloseHandle( cache->lock );
heap_free( cache );
free( cache );
}
return refCount;
}
@ -255,7 +255,7 @@ static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface
if (hr != HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER ))
goto done;
if (!(path = heap_alloc( len * sizeof(WCHAR) )))
if (!(path = malloc( len * sizeof(WCHAR) )))
{
hr = E_OUTOFMEMORY;
goto done;
@ -290,7 +290,7 @@ done:
IAssemblyName_Release( asmname );
if (next) IAssemblyName_Release( next );
if (asmenum) IAssemblyEnum_Release( asmenum );
heap_free( path );
free( path );
cache_unlock( cache );
return hr;
}
@ -372,7 +372,7 @@ static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache
*ppAsmItem = NULL;
if (!(item = heap_alloc(sizeof(*item)))) return E_OUTOFMEMORY;
if (!(item = malloc(sizeof(*item)))) return E_OUTOFMEMORY;
item->IAssemblyCacheItem_iface.lpVtbl = &AssemblyCacheItemVtbl;
item->ref = 1;
@ -395,22 +395,22 @@ static HRESULT copy_file( const WCHAR *src_dir, DWORD src_len, const WCHAR *dst_
DWORD len = lstrlenW( filename );
HRESULT hr = S_OK;
if (!(src_file = heap_alloc( (src_len + len + 1) * sizeof(WCHAR) )))
if (!(src_file = malloc( (src_len + len + 1) * sizeof(WCHAR) )))
return E_OUTOFMEMORY;
memcpy( src_file, src_dir, src_len * sizeof(WCHAR) );
lstrcpyW( src_file + src_len, filename );
if (!(dst_file = heap_alloc( (dst_len + len + 1) * sizeof(WCHAR) )))
if (!(dst_file = malloc( (dst_len + len + 1) * sizeof(WCHAR) )))
{
heap_free( src_file );
free( src_file );
return E_OUTOFMEMORY;
}
memcpy( dst_file, dst_dir, dst_len * sizeof(WCHAR) );
lstrcpyW( dst_file + dst_len, filename );
if (!CopyFileW( src_file, dst_file, FALSE )) hr = HRESULT_FROM_WIN32( GetLastError() );
heap_free( src_file );
heap_free( dst_file );
free( src_file );
free( dst_file );
return hr;
}
@ -483,7 +483,7 @@ static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
get_assembly_directory(asmdir, MAX_PATH, clr_version, architecture);
dst_len += lstrlenW(asmdir) + lstrlenW(name) + lstrlenW(version) + lstrlenW(token);
if (!(dst_dir = heap_alloc(dst_len * sizeof(WCHAR))))
if (!(dst_dir = malloc(dst_len * sizeof(WCHAR))))
{
hr = E_OUTOFMEMORY;
goto done;
@ -523,13 +523,13 @@ static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
}
done:
heap_free(name);
heap_free(token);
heap_free(version);
heap_free(asmpath);
heap_free(dst_dir);
for (i = 0; i < count; i++) heap_free(external_files[i]);
heap_free(external_files);
free(name);
free(token);
free(version);
free(asmpath);
free(dst_dir);
for (i = 0; i < count; i++) free(external_files[i]);
free(external_files);
assembly_release(assembly);
cache_unlock( cache );
return hr;
@ -560,14 +560,14 @@ HRESULT WINAPI CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved
*ppAsmCache = NULL;
if (!(cache = heap_alloc(sizeof(*cache)))) return E_OUTOFMEMORY;
if (!(cache = malloc(sizeof(*cache)))) return E_OUTOFMEMORY;
cache->IAssemblyCache_iface.lpVtbl = &AssemblyCacheVtbl;
cache->ref = 1;
cache->lock = CreateMutexW( NULL, FALSE, cache_mutex_nameW );
if (!cache->lock)
{
heap_free( cache );
free( cache );
return HRESULT_FROM_WIN32( GetLastError() );
}
*ppAsmCache = &cache->IAssemblyCache_iface;
@ -620,7 +620,7 @@ static ULONG WINAPI IAssemblyCacheItemImpl_Release(IAssemblyCacheItem *iface)
TRACE("(%p)->(ref before = %lu)\n", This, refCount + 1);
if (!refCount)
heap_free(This);
free(This);
return refCount;
}

View File

@ -105,10 +105,10 @@ static ULONG WINAPI IAssemblyEnumImpl_Release(IAssemblyEnum *iface)
list_remove(&asmname->entry);
IAssemblyName_Release(asmname->name);
heap_free(asmname);
free(asmname);
}
heap_free(This);
free(This);
}
return refCount;
@ -354,7 +354,7 @@ static HRESULT enum_gac_assemblies(struct list *assemblies, IAssemblyName *name,
}
swprintf(disp, ARRAY_SIZE(disp), name_fmt, parent, version, token);
if (!(asmname = heap_alloc(sizeof(*asmname))))
if (!(asmname = malloc(sizeof(*asmname))))
{
hr = E_OUTOFMEMORY;
break;
@ -364,7 +364,7 @@ static HRESULT enum_gac_assemblies(struct list *assemblies, IAssemblyName *name,
CANOF_PARSE_DISPLAY_NAME, NULL);
if (FAILED(hr))
{
heap_free(asmname);
free(asmname);
break;
}
@ -372,7 +372,7 @@ static HRESULT enum_gac_assemblies(struct list *assemblies, IAssemblyName *name,
if (FAILED(hr))
{
IAssemblyName_Release(asmname->name);
heap_free(asmname);
free(asmname);
break;
}
@ -475,7 +475,7 @@ HRESULT WINAPI CreateAssemblyEnum(IAssemblyEnum **pEnum, IUnknown *pUnkReserved,
if (dwFlags == 0 || dwFlags == ASM_CACHE_ROOT)
return E_INVALIDARG;
if (!(asmenum = heap_alloc(sizeof(*asmenum)))) return E_OUTOFMEMORY;
if (!(asmenum = malloc(sizeof(*asmenum)))) return E_OUTOFMEMORY;
asmenum->IAssemblyEnum_iface.lpVtbl = &AssemblyEnumVtbl;
asmenum->ref = 1;
@ -486,7 +486,7 @@ HRESULT WINAPI CreateAssemblyEnum(IAssemblyEnum **pEnum, IUnknown *pUnkReserved,
hr = enumerate_gac(asmenum, pName);
if (FAILED(hr))
{
heap_free(asmenum);
free(asmenum);
return hr;
}
}

View File

@ -114,12 +114,12 @@ static ULONG WINAPI IAssemblyNameImpl_Release(IAssemblyName *iface)
if (!refCount)
{
heap_free(This->path);
heap_free(This->displayname);
heap_free(This->name);
heap_free(This->culture);
heap_free(This->procarch);
heap_free(This);
free(This->path);
free(This->displayname);
free(This->name);
free(This->culture);
free(This->procarch);
free(This);
}
return refCount;
@ -521,7 +521,7 @@ HRESULT IAssemblyName_SetPath(IAssemblyName *iface, LPCWSTR path)
{
IAssemblyNameImpl *name = unsafe_impl_from_IAssemblyName(iface);
name->path = strdupW(path);
name->path = wcsdup(path);
if (!name->path)
return E_OUTOFMEMORY;
@ -576,12 +576,10 @@ static HRESULT parse_version(IAssemblyNameImpl *name, LPWSTR version)
static HRESULT parse_culture(IAssemblyNameImpl *name, LPCWSTR culture)
{
static const WCHAR empty[] = {0};
if (lstrlenW(culture) == 2)
name->culture = strdupW(culture);
name->culture = wcsdup(culture);
else
name->culture = strdupW(empty);
name->culture = wcsdup(L"");
return S_OK;
}
@ -662,7 +660,7 @@ static WCHAR *parse_value( const WCHAR *str, unsigned int len )
BOOL quoted = FALSE;
unsigned int i = 0;
if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
if (!(ret = malloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
if (*p == '\"')
{
quoted = TRUE;
@ -671,7 +669,7 @@ static WCHAR *parse_value( const WCHAR *str, unsigned int len )
while (*p && *p != '\"') ret[i++] = *p++;
if ((quoted && *p != '\"') || (!quoted && *p == '\"'))
{
heap_free( ret );
free( ret );
return NULL;
}
ret[i] = 0;
@ -687,11 +685,11 @@ static HRESULT parse_display_name(IAssemblyNameImpl *name, LPCWSTR szAssemblyNam
if (!szAssemblyName)
return S_OK;
name->displayname = strdupW(szAssemblyName);
name->displayname = wcsdup(szAssemblyName);
if (!name->displayname)
return E_OUTOFMEMORY;
str = strdupW(szAssemblyName);
str = wcsdup(szAssemblyName);
save = str;
if (!str)
{
@ -709,7 +707,7 @@ static HRESULT parse_display_name(IAssemblyNameImpl *name, LPCWSTR szAssemblyNam
goto done;
}
name->name = strdupW(str);
name->name = wcsdup(str);
if (!name->name)
{
hr = E_OUTOFMEMORY;
@ -768,7 +766,7 @@ static HRESULT parse_display_name(IAssemblyNameImpl *name, LPCWSTR szAssemblyNam
hr = parse_procarch( name, name->procarch );
}
heap_free( value );
free( value );
if (FAILED(hr))
goto done;
@ -777,13 +775,13 @@ static HRESULT parse_display_name(IAssemblyNameImpl *name, LPCWSTR szAssemblyNam
}
done:
heap_free(save);
free(save);
if (FAILED(hr))
{
heap_free(name->displayname);
heap_free(name->name);
heap_free(name->culture);
heap_free(name->procarch);
free(name->displayname);
free(name->name);
free(name->culture);
free(name->procarch);
}
return hr;
}
@ -808,7 +806,7 @@ HRESULT WINAPI CreateAssemblyNameObject(IAssemblyName **ppAssemblyNameObj,
(!szAssemblyName || !*szAssemblyName))
return E_INVALIDARG;
if (!(name = heap_alloc_zero(sizeof(*name)))) return E_OUTOFMEMORY;
if (!(name = calloc(1, sizeof(*name)))) return E_OUTOFMEMORY;
name->IAssemblyName_iface.lpVtbl = &AssemblyNameVtbl;
name->ref = 1;
@ -816,7 +814,7 @@ HRESULT WINAPI CreateAssemblyNameObject(IAssemblyName **ppAssemblyNameObj,
hr = parse_display_name(name, szAssemblyName);
if (FAILED(hr))
{
heap_free(name);
free(name);
return hr;
}

View File

@ -540,7 +540,7 @@ static HRESULT parse_metadata_header(ASSEMBLY *assembly, DWORD *hdrsz)
metadatahdr = (METADATAHDR *)ptr;
if (!(assembly->metadatahdr = heap_alloc(sizeof(*assembly->metadatahdr)))) return E_OUTOFMEMORY;
if (!(assembly->metadatahdr = malloc(sizeof(*assembly->metadatahdr)))) return E_OUTOFMEMORY;
size = FIELD_OFFSET(METADATAHDR, Version);
memcpy(assembly->metadatahdr, metadatahdr, size);
@ -645,9 +645,9 @@ HRESULT assembly_create(ASSEMBLY **out, LPCWSTR file)
*out = NULL;
if (!(assembly = heap_alloc_zero(sizeof(*assembly)))) return E_OUTOFMEMORY;
if (!(assembly = calloc(1, sizeof(*assembly)))) return E_OUTOFMEMORY;
assembly->path = strdupW(file);
assembly->path = wcsdup(file);
if (!assembly->path)
{
hr = E_OUTOFMEMORY;
@ -696,12 +696,12 @@ HRESULT assembly_release(ASSEMBLY *assembly)
if (!assembly)
return S_OK;
heap_free(assembly->metadatahdr);
heap_free(assembly->path);
free(assembly->metadatahdr);
free(assembly->path);
UnmapViewOfFile(assembly->data);
CloseHandle(assembly->hmap);
CloseHandle(assembly->hfile);
heap_free(assembly);
free(assembly);
return S_OK;
}
@ -714,7 +714,7 @@ static LPWSTR assembly_dup_str(const ASSEMBLY *assembly, DWORD index)
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
if ((cpy = heap_alloc(len * sizeof(WCHAR))))
if ((cpy = malloc(len * sizeof(WCHAR))))
MultiByteToWideChar(CP_ACP, 0, str, -1, cpy, len);
return cpy;
@ -749,7 +749,7 @@ HRESULT assembly_get_name(ASSEMBLY *assembly, LPWSTR *name)
HRESULT assembly_get_path(const ASSEMBLY *assembly, LPWSTR *path)
{
WCHAR *cpy = heap_alloc((lstrlenW(assembly->path) + 1) * sizeof(WCHAR));
WCHAR *cpy = malloc((lstrlenW(assembly->path) + 1) * sizeof(WCHAR));
*path = cpy;
if (cpy)
lstrcpyW(cpy, assembly->path);
@ -776,7 +776,7 @@ HRESULT assembly_get_version(ASSEMBLY *assembly, LPWSTR *version)
if (!asmtbl)
return E_FAIL;
if (!(*version = heap_alloc(24 * sizeof(WCHAR))))
if (!(*version = malloc(24 * sizeof(WCHAR))))
return E_OUTOFMEMORY;
swprintf(*version, 24, format, asmtbl->MajorVersion, asmtbl->MinorVersion,
@ -846,7 +846,7 @@ HRESULT assembly_get_pubkey_token(ASSEMBLY *assembly, LPWSTR *token)
for (i = size - 1; i >= size - 8; i--)
tokbytes[size - i - 1] = hashdata[i];
if (!(tok = heap_alloc((TOKEN_LENGTH + 1) * sizeof(WCHAR))))
if (!(tok = malloc((TOKEN_LENGTH + 1) * sizeof(WCHAR))))
{
hr = E_OUTOFMEMORY;
goto done;
@ -890,7 +890,7 @@ HRESULT assembly_get_external_files(ASSEMBLY *assembly, LPWSTR **files, DWORD *c
if (num_rows <= 0)
return S_OK;
if (!(ret = heap_alloc(num_rows * sizeof(WCHAR *)))) return E_OUTOFMEMORY;
if (!(ret = malloc(num_rows * sizeof(WCHAR *)))) return E_OUTOFMEMORY;
for (i = 0; i < num_rows; i++)
{
@ -903,8 +903,8 @@ HRESULT assembly_get_external_files(ASSEMBLY *assembly, LPWSTR **files, DWORD *c
ret[i] = assembly_dup_str(assembly, idx);
if (!ret[i])
{
for (; i >= 0; i--) heap_free(ret[i]);
heap_free(ret);
for (; i >= 0; i--) free(ret[i]);
free(ret);
return E_OUTOFMEMORY;
}
ptr += assembly->stringsz; /* skip Name field */

View File

@ -27,7 +27,6 @@
#include "winbase.h"
#include "winuser.h"
#include "winver.h"
#include "wine/heap.h"
#include <pshpack1.h>
@ -442,19 +441,6 @@ HRESULT assembly_get_external_files(ASSEMBLY *assembly, LPWSTR **files, DWORD *c
extern HRESULT IAssemblyName_SetPath(IAssemblyName *iface, LPCWSTR path) DECLSPEC_HIDDEN;
extern HRESULT IAssemblyName_GetPath(IAssemblyName *iface, LPWSTR buf, ULONG *len) DECLSPEC_HIDDEN;
static inline LPWSTR strdupW(LPCWSTR src)
{
LPWSTR dest;
if (!src)
return NULL;
if ((dest = heap_alloc((lstrlenW(src) + 1) * sizeof(WCHAR))))
lstrcpyW(dest, src);
return dest;
}
#define BYTES_PER_TOKEN 8
#define CHARS_PER_BYTE 2
#define TOKEN_LENGTH (BYTES_PER_TOKEN * CHARS_PER_BYTE + 1)