scrrun: Use CRT 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-01-26 11:33:33 +03:00 committed by Alexandre Julliard
parent b5a3848ee7
commit 5fc49aa2c9
2 changed files with 107 additions and 107 deletions

View File

@ -30,7 +30,6 @@
#include "scrrun_private.h" #include "scrrun_private.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h"
#include "wine/list.h" #include "wine/list.h"
WINE_DEFAULT_DEBUG_CHANNEL(scrrun); WINE_DEFAULT_DEBUG_CHANNEL(scrrun);
@ -177,8 +176,7 @@ static HRESULT add_keyitem_pair(dictionary *dict, VARIANT *key, VARIANT *item)
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
pair = heap_alloc(sizeof(*pair)); if (!(pair = malloc(sizeof(*pair))))
if (!pair)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
pair->hash = V_I4(&hash); pair->hash = V_I4(&hash);
@ -207,7 +205,7 @@ static HRESULT add_keyitem_pair(dictionary *dict, VARIANT *key, VARIANT *item)
failed: failed:
VariantClear(&pair->key); VariantClear(&pair->key);
VariantClear(&pair->item); VariantClear(&pair->item);
heap_free(pair); free(pair);
return hr; return hr;
} }
@ -215,7 +213,7 @@ static void free_keyitem_pair(struct keyitem_pair *pair)
{ {
VariantClear(&pair->key); VariantClear(&pair->key);
VariantClear(&pair->item); VariantClear(&pair->item);
heap_free(pair); free(pair);
} }
static HRESULT WINAPI dict_enum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **obj) static HRESULT WINAPI dict_enum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **obj)
@ -251,10 +249,11 @@ static ULONG WINAPI dict_enum_Release(IEnumVARIANT *iface)
TRACE("(%p)->(%u)\n", This, ref); TRACE("(%p)->(%u)\n", This, ref);
if (!ref) { if (!ref)
{
list_remove(&This->notify); list_remove(&This->notify);
IDictionary_Release(&This->dict->IDictionary_iface); IDictionary_Release(&This->dict->IDictionary_iface);
heap_free(This); free(This);
} }
return ref; return ref;
@ -338,22 +337,22 @@ static const IEnumVARIANTVtbl dictenumvtbl = {
static HRESULT create_dict_enum(dictionary *dict, IUnknown **ret) static HRESULT create_dict_enum(dictionary *dict, IUnknown **ret)
{ {
struct dictionary_enum *This; struct dictionary_enum *object;
*ret = NULL; *ret = NULL;
This = heap_alloc(sizeof(*This)); if (!(object = calloc(1, sizeof(*object))))
if (!This)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
This->IEnumVARIANT_iface.lpVtbl = &dictenumvtbl; object->IEnumVARIANT_iface.lpVtbl = &dictenumvtbl;
This->ref = 1; object->ref = 1;
This->cur = list_head(&dict->pairs); object->cur = list_head(&dict->pairs);
list_add_tail(&dict->notifier, &This->notify); list_add_tail(&dict->notifier, &object->notify);
This->dict = dict; object->dict = dict;
IDictionary_AddRef(&dict->IDictionary_iface); IDictionary_AddRef(&dict->IDictionary_iface);
*ret = (IUnknown*)&This->IEnumVARIANT_iface; *ret = (IUnknown *)&object->IEnumVARIANT_iface;
return S_OK; return S_OK;
} }
@ -423,14 +422,15 @@ static ULONG WINAPI dictionary_AddRef(IDictionary *iface)
static ULONG WINAPI dictionary_Release(IDictionary *iface) static ULONG WINAPI dictionary_Release(IDictionary *iface)
{ {
dictionary *This = impl_from_IDictionary(iface); dictionary *dictionary = impl_from_IDictionary(iface);
ULONG ref = InterlockedDecrement(&This->ref); ULONG ref = InterlockedDecrement(&dictionary->ref);
TRACE("(%p)->(%u)\n", This, ref); TRACE("%p, refcount %u.\n", iface, ref);
if (!ref) { if (!ref)
{
IDictionary_RemoveAll(iface); IDictionary_RemoveAll(iface);
heap_free(This); free(dictionary);
} }
return ref; return ref;
@ -885,27 +885,26 @@ static const struct IDictionaryVtbl dictionary_vtbl =
dictionary_get_HashVal dictionary_get_HashVal
}; };
HRESULT WINAPI Dictionary_CreateInstance(IClassFactory *factory,IUnknown *outer,REFIID riid, void **obj) HRESULT WINAPI Dictionary_CreateInstance(IClassFactory *factory, IUnknown *outer, REFIID riid, void **ret)
{ {
dictionary *This; dictionary *object;
TRACE("(%p, %p, %s, %p)\n", factory, outer, debugstr_guid(riid), obj); TRACE("(%p, %p, %s, %p)\n", factory, outer, debugstr_guid(riid), ret);
*obj = NULL; *ret = NULL;
This = heap_alloc(sizeof(*This)); if (!(object = calloc(1, sizeof(*object))))
if(!This) return E_OUTOFMEMORY; return E_OUTOFMEMORY;
This->IDictionary_iface.lpVtbl = &dictionary_vtbl; object->IDictionary_iface.lpVtbl = &dictionary_vtbl;
This->ref = 1; object->ref = 1;
This->method = BinaryCompare; object->method = BinaryCompare;
This->count = 0; list_init(&object->pairs);
list_init(&This->pairs); list_init(&object->notifier);
list_init(&This->notifier);
memset(This->buckets, 0, sizeof(This->buckets));
init_classinfo(&CLSID_Dictionary, (IUnknown *)&This->IDictionary_iface, &This->classinfo); init_classinfo(&CLSID_Dictionary, (IUnknown *)&object->IDictionary_iface, &object->classinfo);
*obj = &This->IDictionary_iface;
*ret = &object->IDictionary_iface;
return S_OK; return S_OK;
} }

View File

@ -33,7 +33,6 @@
#include "scrrun_private.h" #include "scrrun_private.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(scrrun); WINE_DEFAULT_DEBUG_CHANNEL(scrrun);
@ -317,15 +316,16 @@ static ULONG WINAPI textstream_AddRef(ITextStream *iface)
static ULONG WINAPI textstream_Release(ITextStream *iface) static ULONG WINAPI textstream_Release(ITextStream *iface)
{ {
struct textstream *This = impl_from_ITextStream(iface); struct textstream *stream = impl_from_ITextStream(iface);
ULONG ref = InterlockedDecrement(&This->ref); ULONG ref = InterlockedDecrement(&stream->ref);
TRACE("(%p)->(%d)\n", This, ref);
TRACE("%p, refcount %d.\n", iface, ref);
if (!ref) if (!ref)
{ {
if (This->read_buf_size) heap_free(This->read_buf); if (stream->read_buf_size) free(stream->read_buf);
CloseHandle(This->file); CloseHandle(stream->file);
heap_free(This); free(stream);
} }
return ref; return ref;
@ -462,9 +462,9 @@ static HRESULT append_read_data(struct textstream *stream, const char *buf, size
SetFilePointerEx(stream->file, revert, NULL, FILE_CURRENT); SetFilePointerEx(stream->file, revert, NULL, FILE_CURRENT);
if (!stream->read_buf_size) if (!stream->read_buf_size)
new_buf = heap_alloc(len * sizeof(WCHAR)); new_buf = malloc(len * sizeof(WCHAR));
else else
new_buf = heap_realloc(stream->read_buf, (len + stream->read_buf_size) * sizeof(WCHAR)); new_buf = realloc(stream->read_buf, (len + stream->read_buf_size) * sizeof(WCHAR));
if (!new_buf) return E_OUTOFMEMORY; if (!new_buf) return E_OUTOFMEMORY;
if (stream->unicode) if (stream->unicode)
@ -504,7 +504,7 @@ static BOOL read_from_buffer(struct textstream *stream, size_t len, BSTR *ret, s
if (stream->read_buf_size) if (stream->read_buf_size)
memmove(stream->read_buf, stream->read_buf + len, stream->read_buf_size * sizeof(WCHAR)); memmove(stream->read_buf, stream->read_buf + len, stream->read_buf_size * sizeof(WCHAR));
else else
heap_free(stream->read_buf); free(stream->read_buf);
return TRUE; return TRUE;
} }
@ -622,14 +622,14 @@ static HRESULT textstream_writestr(struct textstream *stream, BSTR text)
char *buffA; char *buffA;
HRESULT hr; HRESULT hr;
buffA = heap_alloc(len); buffA = malloc(len);
if (!buffA) if (!buffA)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
WideCharToMultiByte(CP_ACP, 0, text, SysStringLen(text), buffA, len, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, text, SysStringLen(text), buffA, len, NULL, NULL);
ret = WriteFile(stream->file, buffA, len, &written, NULL); ret = WriteFile(stream->file, buffA, len, &written, NULL);
hr = (ret && written == len) ? S_OK : create_error(GetLastError()); hr = (ret && written == len) ? S_OK : create_error(GetLastError());
heap_free(buffA); free(buffA);
return hr; return hr;
} }
} }
@ -765,21 +765,18 @@ static HRESULT create_textstream(const WCHAR *filename, DWORD disposition, IOMod
return E_INVALIDARG; return E_INVALIDARG;
} }
stream = heap_alloc(sizeof(struct textstream)); if (!(stream = calloc(1, sizeof(*stream))))
if (!stream) return E_OUTOFMEMORY; return E_OUTOFMEMORY;
stream->ITextStream_iface.lpVtbl = &textstreamvtbl; stream->ITextStream_iface.lpVtbl = &textstreamvtbl;
stream->ref = 1; stream->ref = 1;
stream->mode = mode; stream->mode = mode;
stream->eof = FALSE;
stream->read_buf = NULL;
stream->read_buf_size = 0;
stream->file = CreateFileW(filename, access, 0, NULL, disposition, FILE_ATTRIBUTE_NORMAL, NULL); stream->file = CreateFileW(filename, access, 0, NULL, disposition, FILE_ATTRIBUTE_NORMAL, NULL);
if (stream->file == INVALID_HANDLE_VALUE) if (stream->file == INVALID_HANDLE_VALUE)
{ {
HRESULT hr = create_error(GetLastError()); HRESULT hr = create_error(GetLastError());
heap_free(stream); free(stream);
return hr; return hr;
} }
@ -877,12 +874,13 @@ static ULONG WINAPI drive_AddRef(IDrive *iface)
static ULONG WINAPI drive_Release(IDrive *iface) static ULONG WINAPI drive_Release(IDrive *iface)
{ {
struct drive *This = impl_from_IDrive(iface); struct drive *drive = impl_from_IDrive(iface);
ULONG ref = InterlockedDecrement(&This->ref); ULONG ref = InterlockedDecrement(&drive->ref);
TRACE("(%p)->(%d)\n", This, ref);
TRACE("%p, refcount %d.\n", iface, ref);
if (!ref) if (!ref)
heap_free(This); free(drive);
return ref; return ref;
} }
@ -1182,7 +1180,7 @@ static HRESULT create_drive(WCHAR letter, IDrive **drive)
*drive = NULL; *drive = NULL;
object = heap_alloc(sizeof(*object)); object = malloc(sizeof(*object));
if (!object) return E_OUTOFMEMORY; if (!object) return E_OUTOFMEMORY;
object->IDrive_iface.lpVtbl = &drivevtbl; object->IDrive_iface.lpVtbl = &drivevtbl;
@ -1235,7 +1233,7 @@ static ULONG WINAPI foldercoll_enumvariant_Release(IEnumVARIANT *iface)
{ {
IFolderCollection_Release(&This->data.u.foldercoll.coll->IFolderCollection_iface); IFolderCollection_Release(&This->data.u.foldercoll.coll->IFolderCollection_iface);
FindClose(This->data.u.foldercoll.find); FindClose(This->data.u.foldercoll.find);
heap_free(This); free(This);
} }
return ref; return ref;
@ -1392,7 +1390,7 @@ static HRESULT create_foldercoll_enum(struct foldercollection *collection, IUnkn
*newenum = NULL; *newenum = NULL;
This = heap_alloc(sizeof(*This)); This = malloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY; if (!This) return E_OUTOFMEMORY;
This->IEnumVARIANT_iface.lpVtbl = &foldercollenumvariantvtbl; This->IEnumVARIANT_iface.lpVtbl = &foldercollenumvariantvtbl;
@ -1417,7 +1415,7 @@ static ULONG WINAPI filecoll_enumvariant_Release(IEnumVARIANT *iface)
{ {
IFileCollection_Release(&This->data.u.filecoll.coll->IFileCollection_iface); IFileCollection_Release(&This->data.u.filecoll.coll->IFileCollection_iface);
FindClose(This->data.u.filecoll.find); FindClose(This->data.u.filecoll.find);
heap_free(This); free(This);
} }
return ref; return ref;
@ -1534,7 +1532,7 @@ static HRESULT create_filecoll_enum(struct filecollection *collection, IUnknown
*newenum = NULL; *newenum = NULL;
This = heap_alloc(sizeof(*This)); This = malloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY; if (!This) return E_OUTOFMEMORY;
This->IEnumVARIANT_iface.lpVtbl = &filecollenumvariantvtbl; This->IEnumVARIANT_iface.lpVtbl = &filecollenumvariantvtbl;
@ -1558,7 +1556,7 @@ static ULONG WINAPI drivecoll_enumvariant_Release(IEnumVARIANT *iface)
if (!ref) if (!ref)
{ {
IDriveCollection_Release(&This->data.u.drivecoll.coll->IDriveCollection_iface); IDriveCollection_Release(&This->data.u.drivecoll.coll->IDriveCollection_iface);
heap_free(This); free(This);
} }
return ref; return ref;
@ -1657,7 +1655,7 @@ static HRESULT create_drivecoll_enum(struct drivecollection *collection, IUnknow
*newenum = NULL; *newenum = NULL;
This = heap_alloc(sizeof(*This)); This = malloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY; if (!This) return E_OUTOFMEMORY;
This->IEnumVARIANT_iface.lpVtbl = &drivecollenumvariantvtbl; This->IEnumVARIANT_iface.lpVtbl = &drivecollenumvariantvtbl;
@ -1713,7 +1711,7 @@ static ULONG WINAPI foldercoll_Release(IFolderCollection *iface)
if (!ref) if (!ref)
{ {
SysFreeString(This->path); SysFreeString(This->path);
heap_free(This); free(This);
} }
return ref; return ref;
@ -1854,7 +1852,7 @@ static HRESULT create_foldercoll(BSTR path, IFolderCollection **folders)
*folders = NULL; *folders = NULL;
This = heap_alloc(sizeof(struct foldercollection)); This = malloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY; if (!This) return E_OUTOFMEMORY;
This->IFolderCollection_iface.lpVtbl = &foldercollvtbl; This->IFolderCollection_iface.lpVtbl = &foldercollvtbl;
@ -1862,7 +1860,7 @@ static HRESULT create_foldercoll(BSTR path, IFolderCollection **folders)
This->path = SysAllocString(path); This->path = SysAllocString(path);
if (!This->path) if (!This->path)
{ {
heap_free(This); free(This);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -1914,7 +1912,7 @@ static ULONG WINAPI filecoll_Release(IFileCollection *iface)
if (!ref) if (!ref)
{ {
SysFreeString(This->path); SysFreeString(This->path);
heap_free(This); free(This);
} }
return ref; return ref;
@ -2047,7 +2045,7 @@ static HRESULT create_filecoll(BSTR path, IFileCollection **files)
*files = NULL; *files = NULL;
This = heap_alloc(sizeof(*This)); This = malloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY; if (!This) return E_OUTOFMEMORY;
This->IFileCollection_iface.lpVtbl = &filecollectionvtbl; This->IFileCollection_iface.lpVtbl = &filecollectionvtbl;
@ -2055,7 +2053,7 @@ static HRESULT create_filecoll(BSTR path, IFileCollection **files)
This->path = SysAllocString(path); This->path = SysAllocString(path);
if (!This->path) if (!This->path)
{ {
heap_free(This); free(This);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -2104,7 +2102,7 @@ static ULONG WINAPI drivecoll_Release(IDriveCollection *iface)
TRACE("(%p)->(%d)\n", This, ref); TRACE("(%p)->(%d)\n", This, ref);
if (!ref) if (!ref)
heap_free(This); free(This);
return ref; return ref;
} }
@ -2219,7 +2217,7 @@ static HRESULT create_drivecoll(IDriveCollection **drives)
*drives = NULL; *drives = NULL;
This = heap_alloc(sizeof(*This)); This = malloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY; if (!This) return E_OUTOFMEMORY;
This->IDriveCollection_iface.lpVtbl = &drivecollectionvtbl; This->IDriveCollection_iface.lpVtbl = &drivecollectionvtbl;
@ -2276,7 +2274,7 @@ static ULONG WINAPI folder_Release(IFolder *iface)
if (!ref) if (!ref)
{ {
SysFreeString(This->path); SysFreeString(This->path);
heap_free(This); free(This);
} }
return ref; return ref;
@ -2568,26 +2566,26 @@ static const IFolderVtbl foldervtbl = {
HRESULT create_folder(const WCHAR *path, IFolder **folder) HRESULT create_folder(const WCHAR *path, IFolder **folder)
{ {
struct folder *This; struct folder *object;
*folder = NULL; *folder = NULL;
TRACE("%s\n", debugstr_w(path)); TRACE("%s\n", debugstr_w(path));
This = heap_alloc(sizeof(struct folder)); if (!(object = malloc(sizeof(*object))))
if (!This) return E_OUTOFMEMORY; return E_OUTOFMEMORY;
This->IFolder_iface.lpVtbl = &foldervtbl; object->IFolder_iface.lpVtbl = &foldervtbl;
This->ref = 1; object->ref = 1;
This->path = SysAllocString(path); object->path = SysAllocString(path);
if (!This->path) if (!object->path)
{ {
heap_free(This); free(object);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
init_classinfo(&CLSID_Folder, (IUnknown *)&This->IFolder_iface, &This->classinfo); init_classinfo(&CLSID_Folder, (IUnknown *)&object->IFolder_iface, &object->classinfo);
*folder = &This->IFolder_iface; *folder = &object->IFolder_iface;
return S_OK; return S_OK;
} }
@ -2629,15 +2627,15 @@ static ULONG WINAPI file_AddRef(IFile *iface)
static ULONG WINAPI file_Release(IFile *iface) static ULONG WINAPI file_Release(IFile *iface)
{ {
struct file *This = impl_from_IFile(iface); struct file *file = impl_from_IFile(iface);
LONG ref = InterlockedDecrement(&This->ref); LONG ref = InterlockedDecrement(&file->ref);
TRACE("(%p) ref=%d\n", This, ref); TRACE("%p, refcount %d.\n", iface, ref);
if (!ref) if (!ref)
{ {
heap_free(This->path); free(file->path);
heap_free(This); free(file);
} }
return ref; return ref;
@ -2942,7 +2940,7 @@ static HRESULT create_file(BSTR path, IFile **file)
*file = NULL; *file = NULL;
f = heap_alloc(sizeof(struct file)); f = malloc(sizeof(struct file));
if(!f) if(!f)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -2950,28 +2948,31 @@ static HRESULT create_file(BSTR path, IFile **file)
f->ref = 1; f->ref = 1;
len = GetFullPathNameW(path, 0, NULL, NULL); len = GetFullPathNameW(path, 0, NULL, NULL);
if(!len) { if (!len)
heap_free(f); {
free(f);
return E_FAIL; return E_FAIL;
} }
f->path = heap_alloc(len*sizeof(WCHAR)); f->path = malloc(len*sizeof(WCHAR));
if(!f->path) { if(!f->path)
heap_free(f); {
free(f);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
if(!GetFullPathNameW(path, len, f->path, NULL)) { if (!GetFullPathNameW(path, len, f->path, NULL))
heap_free(f->path); {
heap_free(f); free(f->path);
free(f);
return E_FAIL; return E_FAIL;
} }
attrs = GetFileAttributesW(f->path); attrs = GetFileAttributesW(f->path);
if(attrs==INVALID_FILE_ATTRIBUTES || if (attrs == INVALID_FILE_ATTRIBUTES || (attrs & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)))
(attrs&(FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE))) { {
heap_free(f->path); free(f->path);
heap_free(f); free(f);
return create_error(GetLastError()); return create_error(GetLastError());
} }
@ -3931,22 +3932,22 @@ static HRESULT WINAPI filesys_GetFileVersion(IFileSystem3 *iface, BSTR name, BST
if (!len) if (!len)
return HRESULT_FROM_WIN32(GetLastError()); return HRESULT_FROM_WIN32(GetLastError());
ptr = heap_alloc(len); ptr = malloc(len);
if (!GetFileVersionInfoW(name, 0, len, ptr)) if (!GetFileVersionInfoW(name, 0, len, ptr))
{ {
heap_free(ptr); free(ptr);
return HRESULT_FROM_WIN32(GetLastError()); return HRESULT_FROM_WIN32(GetLastError());
} }
ret = VerQueryValueW(ptr, L"\\", (void **)&info, &len); ret = VerQueryValueW(ptr, L"\\", (void **)&info, &len);
if (!ret) if (!ret)
{ {
heap_free(ptr); free(ptr);
return HRESULT_FROM_WIN32(GetLastError()); return HRESULT_FROM_WIN32(GetLastError());
} }
get_versionstring(info, ver); get_versionstring(info, ver);
heap_free(ptr); free(ptr);
*version = SysAllocString(ver); *version = SysAllocString(ver);
TRACE("version=%s\n", debugstr_w(ver)); TRACE("version=%s\n", debugstr_w(ver));