From: Rémi Bernon rbernon@codeweavers.com
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- include/winbase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/winbase.h b/include/winbase.h index f853392cced..a400816c4d3 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -2379,7 +2379,7 @@ WINBASEAPI SIZE_T WINAPI HeapCompact(HANDLE,DWORD); WINBASEAPI HANDLE WINAPI HeapCreate(DWORD,SIZE_T,SIZE_T); WINBASEAPI BOOL WINAPI HeapDestroy(HANDLE); WINBASEAPI BOOL WINAPI HeapLock(HANDLE); -WINBASEAPI LPVOID WINAPI HeapReAlloc(HANDLE,DWORD,LPVOID,SIZE_T) __WINE_ALLOC_SIZE(4) __WINE_DEALLOC(HeapFree); +WINBASEAPI LPVOID WINAPI HeapReAlloc(HANDLE,DWORD,LPVOID,SIZE_T) __WINE_ALLOC_SIZE(4) __WINE_DEALLOC(HeapFree,3); WINBASEAPI BOOL WINAPI HeapQueryInformation(HANDLE,HEAP_INFORMATION_CLASS,PVOID,SIZE_T,PSIZE_T); WINBASEAPI BOOL WINAPI HeapSetInformation(HANDLE,HEAP_INFORMATION_CLASS,PVOID,SIZE_T); WINBASEAPI SIZE_T WINAPI HeapSize(HANDLE,DWORD,LPCVOID);
From: Rémi Bernon rbernon@codeweavers.com
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- include/winternl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/winternl.h b/include/winternl.h index ca265cf074c..bfb211128a8 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -4458,7 +4458,7 @@ NTSYSAPI NTSTATUS WINAPI RtlQueueWorkItem(PRTL_WORK_ITEM_ROUTINE,PVOID,ULONG); NTSYSAPI void WINAPI RtlRaiseException(PEXCEPTION_RECORD); NTSYSAPI void WINAPI RtlRaiseStatus(NTSTATUS); NTSYSAPI ULONG WINAPI RtlRandom(PULONG); -NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE,ULONG,PVOID,SIZE_T) __WINE_ALLOC_SIZE(4); +NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE,ULONG,PVOID,SIZE_T) __WINE_ALLOC_SIZE(4) __WINE_DEALLOC(RtlFreeHeap,3); NTSYSAPI NTSTATUS WINAPI RtlRegisterWait(PHANDLE,HANDLE,RTL_WAITORTIMERCALLBACKFUNC,PVOID,ULONG,ULONG); NTSYSAPI void WINAPI RtlReleaseActivationContext(HANDLE); NTSYSAPI void WINAPI RtlReleasePath(PWSTR);
From: Rémi Bernon rbernon@codeweavers.com
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/wineoss.drv/mmdevdrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/wineoss.drv/mmdevdrv.c b/dlls/wineoss.drv/mmdevdrv.c index 26ff60aeb2a..dbd9c5a0490 100644 --- a/dlls/wineoss.drv/mmdevdrv.c +++ b/dlls/wineoss.drv/mmdevdrv.c @@ -399,7 +399,7 @@ HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids_out, GUID **gu ids[i] = HeapAlloc(GetProcessHeap(), 0, name_size); oss_dev = HeapAlloc(GetProcessHeap(), 0, offsetof(OSSDevice, devnode[dev_size])); if(!ids[i] || !oss_dev){ - HeapFree(GetProcessHeap, 0, oss_dev); + HeapFree(GetProcessHeap(), 0, oss_dev); params.result = E_OUTOFMEMORY; goto end; }
From: Rémi Bernon rbernon@codeweavers.com
Using function pointers to remove the malloc attributes.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/kernel32/tests/heap.c | 50 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index d9cae9f723b..8ef0bfc3668 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -44,10 +44,14 @@ /* use function pointers to avoid warnings for invalid parameter tests */ static LPVOID (WINAPI *pHeapAlloc)(HANDLE,DWORD,SIZE_T); static LPVOID (WINAPI *pHeapReAlloc)(HANDLE,DWORD,LPVOID,SIZE_T); +static BOOL (WINAPI *pHeapFree)(HANDLE,DWORD,LPVOID); static BOOL (WINAPI *pGetPhysicallyInstalledSystemMemory)( ULONGLONG * ); static BOOLEAN (WINAPI *pRtlGetUserInfoHeap)(HANDLE,ULONG,void*,void**,ULONG*); static BOOLEAN (WINAPI *pRtlSetUserValueHeap)(HANDLE,ULONG,void*,void*); static BOOLEAN (WINAPI *pRtlSetUserFlagsHeap)(HANDLE,ULONG,void*,ULONG,ULONG); +static HGLOBAL (WINAPI *pGlobalAlloc)(UINT,SIZE_T); +static HGLOBAL (WINAPI *pGlobalFree)(HGLOBAL); +static HGLOBAL (WINAPI *pLocalFree)(HLOCAL);
#define MAKE_FUNC(f) static typeof(f) *p ## f MAKE_FUNC( HeapQueryInformation ); @@ -64,10 +68,14 @@ static void load_functions(void) #define LOAD_FUNC(m, f) p ## f = (void *)GetProcAddress( m, #f ); LOAD_FUNC( kernel32, HeapAlloc ); LOAD_FUNC( kernel32, HeapReAlloc ); + LOAD_FUNC( kernel32, HeapFree ); LOAD_FUNC( kernel32, HeapQueryInformation ); LOAD_FUNC( kernel32, HeapSetInformation ); LOAD_FUNC( kernel32, GetPhysicallyInstalledSystemMemory ); + LOAD_FUNC( kernel32, GlobalAlloc ); LOAD_FUNC( kernel32, GlobalFlags ); + LOAD_FUNC( kernel32, GlobalFree ); + LOAD_FUNC( kernel32, LocalFree ); LOAD_FUNC( ntdll, RtlGetNtGlobalFlags ); LOAD_FUNC( ntdll, RtlGetUserInfoHeap ); LOAD_FUNC( ntdll, RtlSetUserValueHeap ); @@ -287,7 +295,7 @@ static void test_HeapCreate(void) ok( !ptr1, "HeapReAlloc succeeded\n" ); ret = HeapValidate( heap, 0, ptr ); ok( ret, "HeapValidate failed, error %lu\n", GetLastError() ); - ret = HeapFree( heap, 0, ptr ); + ret = pHeapFree( heap, 0, ptr ); ok( ret, "HeapFree failed, error %lu\n", GetLastError() ); SetLastError( 0xdeadbeef ); ret = HeapValidate( heap, 0, ptr ); @@ -1344,12 +1352,12 @@ static void test_GlobalAlloc(void) ok( !!mem, "GlobalReAlloc failed, error %lu\n", GetLastError() ); size = GlobalSize( mem ); ok( size >= 10 && size <= 16, "GlobalSize returned %Iu\n", size ); - tmp_mem = GlobalFree( mem ); + tmp_mem = pGlobalFree( mem ); ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); size = GlobalSize( mem ); ok( size == 0, "GlobalSize returned %Iu\n", size );
- mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); + mem = pGlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); entry = mem_entry_from_HANDLE( mem ); size = GlobalSize( mem ); @@ -1361,7 +1369,7 @@ static void test_GlobalAlloc(void) mem = GlobalFree( mem ); ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() );
- mem = GlobalAlloc( GMEM_MOVEABLE, 0 ); + mem = pGlobalAlloc( GMEM_MOVEABLE, 0 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); entry = mem_entry_from_HANDLE( mem ); size = GlobalSize( mem ); @@ -1386,7 +1394,7 @@ static void test_GlobalAlloc(void) tmp_mem = GlobalFree( mem ); ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() );
- mem = GlobalAlloc( GMEM_MOVEABLE, alloc_size ); + mem = pGlobalAlloc( GMEM_MOVEABLE, alloc_size ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); ok( ((UINT_PTR)mem & sizeof(void *)), "got unexpected entry align\n" ); ok( !((UINT_PTR)mem & (sizeof(void *) - 1)), "got unexpected entry align\n" ); @@ -1444,14 +1452,14 @@ static void test_GlobalAlloc(void) ok( !ret, "GlobalUnlock succeeded, error %lu\n", GetLastError() ); ok( entry->flags == 0x3, "got unexpected flags %#Ix\n", entry->flags );
- tmp_mem = GlobalFree( mem ); + tmp_mem = pGlobalFree( mem ); ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); ok( !!entry->flags, "got unexpected flags %#Ix\n", entry->flags ); ok( !((UINT_PTR)entry->flags & sizeof(void *)), "got unexpected ptr align\n" ); ok( !((UINT_PTR)entry->flags & (sizeof(void *) - 1)), "got unexpected ptr align\n" ); ok( !entry->ptr, "got unexpected ptr %p\n", entry->ptr );
- mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); + mem = pGlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 0 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); entry = mem_entry_from_HANDLE( mem ); ok( entry->flags == 0xf, "got unexpected flags %#Ix\n", entry->flags ); @@ -1461,7 +1469,7 @@ static void test_GlobalAlloc(void) mem = GlobalFree( mem ); ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() );
- mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 1 ); + mem = pGlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 1 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); entry = mem_entry_from_HANDLE( mem ); ok( entry->flags == 0x7, "got unexpected flags %#Ix\n", entry->flags ); @@ -1471,7 +1479,7 @@ static void test_GlobalAlloc(void) mem = GlobalFree( mem ); ok( !mem, "GlobalFree failed, error %lu\n", GetLastError() );
- mem = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE | GMEM_DDESHARE, 1 ); + mem = pGlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE | GMEM_DDESHARE, 1 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); entry = mem_entry_from_HANDLE( mem ); ok( entry->flags == 0x8007, "got unexpected flags %#Ix\n", entry->flags ); @@ -1515,12 +1523,12 @@ static void test_GlobalAlloc(void)
mem = GlobalAlloc( GMEM_DDESHARE, 100 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); - tmp_mem = GlobalFree( mem ); + tmp_mem = pGlobalFree( mem ); ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); if (sizeof(void *) != 8) /* crashes on 64-bit */ { SetLastError( 0xdeadbeef ); - tmp_mem = GlobalFree( mem ); + tmp_mem = pGlobalFree( mem ); ok( tmp_mem == mem, "GlobalFree succeeded\n" ); ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() );
@@ -1533,10 +1541,10 @@ static void test_GlobalAlloc(void) /* freed handles are caught */ mem = GlobalAlloc( GMEM_MOVEABLE, 256 ); ok( !!mem, "GlobalAlloc failed, error %lu\n", GetLastError() ); - tmp_mem = GlobalFree( mem ); + tmp_mem = pGlobalFree( mem ); ok( !tmp_mem, "GlobalFree failed, error %lu\n", GetLastError() ); SetLastError( 0xdeadbeef ); - tmp_mem = GlobalFree( mem ); + tmp_mem = pGlobalFree( mem ); ok( tmp_mem == mem, "GlobalFree succeeded\n" ); ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); SetLastError( 0xdeadbeef ); @@ -1567,7 +1575,7 @@ static void test_GlobalAlloc(void)
/* invalid handles are caught */ SetLastError( 0xdeadbeef ); - tmp_mem = GlobalFree( invalid_mem ); + tmp_mem = pGlobalFree( invalid_mem ); ok( tmp_mem == invalid_mem, "GlobalFree succeeded\n" ); ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); SetLastError( 0xdeadbeef ); @@ -1594,7 +1602,7 @@ static void test_GlobalAlloc(void)
/* invalid pointers are caught */ SetLastError( 0xdeadbeef ); - tmp_mem = GlobalFree( invalid_ptr ); + tmp_mem = pGlobalFree( invalid_ptr ); ok( tmp_mem == invalid_ptr, "GlobalFree succeeded\n" ); todo_wine ok( GetLastError() == ERROR_NOACCESS, "got error %lu\n", GetLastError() ); @@ -1852,7 +1860,7 @@ static void test_LocalAlloc(void) ok( !!mem, "LocalReAlloc failed, error %lu\n", GetLastError() ); size = LocalSize( mem ); ok( size >= 10 && size <= 16, "LocalSize returned %Iu\n", size ); - tmp_mem = LocalFree( mem ); + tmp_mem = pLocalFree( mem ); ok( !tmp_mem, "LocalFree failed, error %lu\n", GetLastError() ); size = LocalSize( mem ); ok( size == 0, "LocalSize returned %Iu\n", size ); @@ -1889,10 +1897,10 @@ static void test_LocalAlloc(void) /* freed handles are caught */ mem = LocalAlloc( LMEM_MOVEABLE, 256 ); ok( !!mem, "LocalAlloc failed, error %lu\n", GetLastError() ); - tmp_mem = LocalFree( mem ); + tmp_mem = pLocalFree( mem ); ok( !tmp_mem, "LocalFree failed, error %lu\n", GetLastError() ); SetLastError( 0xdeadbeef ); - tmp_mem = LocalFree( mem ); + tmp_mem = pLocalFree( mem ); ok( tmp_mem == mem, "LocalFree succeeded\n" ); ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); SetLastError( 0xdeadbeef ); @@ -1922,7 +1930,7 @@ static void test_LocalAlloc(void)
/* invalid handles are caught */ SetLastError( 0xdeadbeef ); - tmp_mem = LocalFree( invalid_mem ); + tmp_mem = pLocalFree( invalid_mem ); ok( tmp_mem == invalid_mem, "LocalFree succeeded\n" ); ok( GetLastError() == ERROR_INVALID_HANDLE, "got error %lu\n", GetLastError() ); SetLastError( 0xdeadbeef ); @@ -1948,7 +1956,7 @@ static void test_LocalAlloc(void)
/* invalid pointers are caught */ SetLastError( 0xdeadbeef ); - tmp_mem = LocalFree( invalid_ptr ); + tmp_mem = pLocalFree( invalid_ptr ); ok( tmp_mem == invalid_ptr, "LocalFree succeeded\n" ); todo_wine ok( GetLastError() == ERROR_NOACCESS, "got error %lu\n", GetLastError() ); @@ -2444,7 +2452,7 @@ static void test_heap_checks( DWORD flags ) ok( p != NULL, "HeapAlloc failed\n" ); memset( p, 0xcc, 37 );
- ret = HeapFree( GetProcessHeap(), 0, p ); + ret = pHeapFree( GetProcessHeap(), 0, p ); ok( ret, "HeapFree failed\n" );
if (flags & HEAP_FREE_CHECKING_ENABLED)
From: Rémi Bernon rbernon@codeweavers.com
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/kernelbase/memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c index 416d7b52a16..b89ab04a38f 100644 --- a/dlls/kernelbase/memory.c +++ b/dlls/kernelbase/memory.c @@ -712,7 +712,7 @@ static struct kernelbase_global_data global_data = {0};
static inline struct mem_entry *unsafe_mem_from_HLOCAL( HLOCAL handle ) { - struct mem_entry *mem = CONTAINING_RECORD( handle, struct mem_entry, ptr ); + struct mem_entry *mem = CONTAINING_RECORD( *(volatile HANDLE *)&handle, struct mem_entry, ptr ); struct kernelbase_global_data *data = &global_data; if (((UINT_PTR)handle & ((sizeof(void *) << 1) - 1)) != sizeof(void *)) return NULL; if (mem < data->mem_entries || mem >= data->mem_entries_end) return NULL; @@ -831,7 +831,7 @@ HLOCAL WINAPI DECLSPEC_HOTPATCH LocalAlloc( UINT flags, SIZE_T size ) return handle;
failed: - if (mem) LocalFree( handle ); + if (mem) LocalFree( *(volatile HANDLE *)&handle ); SetLastError( ERROR_NOT_ENOUGH_MEMORY ); return 0; }