From 2788057a2dce7513a1f75c320966185b7f680082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 8 Oct 2023 16:00:22 +0200 Subject: [PATCH] [SETUPAPI] diskspace.c: Fix memory allocations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- dll/win32/setupapi/diskspace.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dll/win32/setupapi/diskspace.c b/dll/win32/setupapi/diskspace.c index dd1383ee31b..c279dcd05a3 100644 --- a/dll/win32/setupapi/diskspace.c +++ b/dll/win32/setupapi/diskspace.c @@ -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; }