[SETUPAPI] diskspace.c: Fix memory allocations.

- The allocated file element should use the CRT allocator, as it is how
  it gets freed in SetupDestroyDiskSpaceList (and SetupDuplicateDiskSpaceListW)

- GetFullPathNameW() takes the buffer size in number of characters, not
  in bytes.

Fix for wine-staging commit:
setupapi: Implement SetupAddToDiskSpaceList.
wine-staging patch by Michael Müller <michael@fds-team.de>
This commit is contained in:
Hermès Bélusca-Maïto 2023-10-08 16:00:22 +02:00
parent 5adf1d4575
commit b28264a9cc
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -527,8 +527,13 @@ BOOL WINAPI SetupAddToDiskSpaceListW(HDSKSPC diskspace, PCWSTR targetfile,
return FALSE;
}
#ifdef __REACTOS__ // BUGFIX
size++; // Add terminating NUL
fullpathW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
#else
size = (size+1) * sizeof(WCHAR);
fullpathW = HeapAlloc(GetProcessHeap(), 0, size);
#endif
if (!GetFullPathNameW(targetfile, size, fullpathW, NULL))
{
@ -551,7 +556,11 @@ BOOL WINAPI SetupAddToDiskSpaceListW(HDSKSPC diskspace, PCWSTR targetfile,
if (&file->entry == &list->files)
{
#ifdef __REACTOS__ // BUGFIX
file = malloc(sizeof(*file));
#else
file = HeapAlloc(GetProcessHeap(), 0, sizeof(*file));
#endif
if (!file)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@ -562,7 +571,11 @@ BOOL WINAPI SetupAddToDiskSpaceListW(HDSKSPC diskspace, PCWSTR targetfile,
if (!file->path)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
#ifdef __REACTOS__ // BUGFIX
free(file);
#else
HeapFree(GetProcessHeap(), 0, file);
#endif
goto done;
}