Alexandre Julliard : ntdll: Use malloc() to allocate the system processor information.
Alexandre Julliard
julliard at winehq.org
Tue Jul 14 16:23:37 CDT 2020
Module: wine
Branch: master
Commit: 242dc8989a993d1b3807f437fbac7b92707b6e28
URL: https://source.winehq.org/git/wine.git/?a=commit;h=242dc8989a993d1b3807f437fbac7b92707b6e28
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Jul 14 10:35:14 2020 +0200
ntdll: Use malloc() to allocate the system processor information.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/unix/system.c | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c
index eedd67fba1..835cf8d134 100644
--- a/dlls/ntdll/unix/system.c
+++ b/dlls/ntdll/unix/system.c
@@ -2182,6 +2182,11 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
ret = STATUS_INFO_LENGTH_MISMATCH;
break;
}
+ if (!(sppi = calloc( out_cpus, sizeof(*sppi) )))
+ {
+ ret = STATUS_NO_MEMORY;
+ break;
+ }
else
#ifdef __APPLE__
{
@@ -2196,8 +2201,6 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
{
int i;
cpus = min(cpus,out_cpus);
- len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
- sppi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
for (i = 0; i < cpus; i++)
{
sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
@@ -2214,7 +2217,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
{
unsigned long clk_tck = sysconf(_SC_CLK_TCK);
unsigned long usr,nice,sys,idle,remainder[8];
- int i, count;
+ int i, count, id;
char name[32];
char line[255];
@@ -2230,17 +2233,12 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
for (i = 0; i + 5 < count; ++i) sys += remainder[i];
sys += idle;
usr += nice;
- cpus = atoi( name + 3 ) + 1;
- if (cpus > out_cpus) break;
- len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
- if (sppi)
- sppi = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sppi, len );
- else
- sppi = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
-
- sppi[cpus-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
- sppi[cpus-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
- sppi[cpus-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
+ id = atoi( name + 3 ) + 1;
+ if (id > out_cpus) break;
+ if (id > cpus) cpus = id;
+ sppi[id-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
+ sppi[id-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
+ sppi[id-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
}
fclose(cpuinfo);
}
@@ -2251,8 +2249,6 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
static int i = 1;
unsigned int n;
cpus = min(NtCurrentTeb()->Peb->NumberOfProcessors, out_cpus);
- len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
- sppi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
/* many programs expect these values to change so fake change */
for (n = 0; n < cpus; n++)
@@ -2264,6 +2260,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
i++;
}
+ len = sizeof(*sppi) * cpus;
if (size >= len)
{
if (!info) ret = STATUS_ACCESS_VIOLATION;
@@ -2271,7 +2268,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
}
else ret = STATUS_INFO_LENGTH_MISMATCH;
- RtlFreeHeap(GetProcessHeap(),0,sppi);
+ free( sppi );
break;
}
More information about the wine-cvs
mailing list