summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 10:01:38 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 10:01:38 -0800
commit0da43ac0a33c71329c6116aa5aee405d0298fd55 (patch)
treeed1922a28fb33b82554d1f00cdbbbd776886678b
parent11ba1c8e6e92e0fd5a04d03873c839766ec49401 (diff)
downloadpsutil-0da43ac0a33c71329c6116aa5aee405d0298fd55.tar.gz
win: provide alias for HeapAlloc()
-rw-r--r--psutil/arch/windows/process_handles.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/psutil/arch/windows/process_handles.c b/psutil/arch/windows/process_handles.c
index 8d909128..5877715e 100644
--- a/psutil/arch/windows/process_handles.c
+++ b/psutil/arch/windows/process_handles.c
@@ -25,6 +25,7 @@ ULONG g_dwSize = 0;
ULONG g_dwLength = 0;
#define NTQO_TIMEOUT 100
+#define MALLOC_ZERO(x) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (x))
static VOID
@@ -131,16 +132,14 @@ psutil_get_open_files_ntqueryobject(DWORD dwPid, HANDLE hProcess) {
do {
if (pHandleInfo != NULL) {
- HeapFree(GetProcessHeap(), 0, pHandleInfo);
+ FREE(pHandleInfo);
pHandleInfo = NULL;
}
// NtQuerySystemInformation won't give us the correct buffer size,
// so we guess by doubling the buffer size.
dwInfoSize *= 2;
- pHandleInfo = HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- dwInfoSize);
+ pHandleInfo = MALLOC_ZERO(dwInfoSize);
if (pHandleInfo == NULL) {
PyErr_NoMemory();
@@ -185,7 +184,7 @@ psutil_get_open_files_ntqueryobject(DWORD dwPid, HANDLE hProcess) {
do {
// Release any previously allocated buffer
if (g_pNameBuffer != NULL) {
- HeapFree(GetProcessHeap(), 0, g_pNameBuffer);
+ FREE(g_pNameBuffer);
g_pNameBuffer = NULL;
g_dwSize = 0;
}
@@ -197,9 +196,7 @@ psutil_get_open_files_ntqueryobject(DWORD dwPid, HANDLE hProcess) {
g_dwSize = g_dwLength;
if (g_dwSize > 0) {
- g_pNameBuffer = HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- g_dwSize);
+ g_pNameBuffer = MALLOC_ZERO(g_dwSize);
if (g_pNameBuffer == NULL)
goto loop_cleanup;
@@ -236,7 +233,7 @@ loop_cleanup:
Py_XDECREF(py_path);
py_path = NULL;
if (g_pNameBuffer != NULL)
- HeapFree(GetProcessHeap(), 0, g_pNameBuffer);
+ FREE(g_pNameBuffer);
g_pNameBuffer = NULL;
g_dwSize = 0;
g_dwLength = 0;
@@ -247,7 +244,7 @@ loop_cleanup:
cleanup:
if (g_pNameBuffer != NULL)
- HeapFree(GetProcessHeap(), 0, g_pNameBuffer);
+ FREE(g_pNameBuffer);
g_pNameBuffer = NULL;
g_dwSize = 0;
g_dwLength = 0;
@@ -257,7 +254,7 @@ cleanup:
g_hFile = NULL;
if (pHandleInfo != NULL)
- HeapFree(GetProcessHeap(), 0, pHandleInfo);
+ FREE(pHandleInfo);
pHandleInfo = NULL;
if (error) {
@@ -299,16 +296,14 @@ psutil_get_open_files_getmappedfilename(DWORD dwPid, HANDLE hProcess) {
do {
if (pHandleInfo != NULL) {
- HeapFree(GetProcessHeap(), 0, pHandleInfo);
+ FREE(pHandleInfo);
pHandleInfo = NULL;
}
// NtQuerySystemInformation won't give us the correct buffer size,
// so we guess by doubling the buffer size.
dwInfoSize *= 2;
- pHandleInfo = HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- dwInfoSize);
+ pHandleInfo = MALLOC_ZERO(dwInfoSize);
if (pHandleInfo == NULL) {
PyErr_NoMemory();
@@ -402,7 +397,7 @@ cleanup:
CloseHandle(hFile);
hFile = NULL;
if (pHandleInfo != NULL)
- HeapFree(GetProcessHeap(), 0, pHandleInfo);
+ FREE(pHandleInfo);
pHandleInfo = NULL;
if (error) {
Py_XDECREF(py_retlist);