summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 03:15:32 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 03:15:32 +0100
commit2559600d57c06c133f6b48c4907823c3bc8378aa (patch)
tree27229ad415f965bb384ef66569c8b49d03020b82
parent9083ea9ad5f6b72eccd94faffcd12ae287b93cce (diff)
downloadpsutil-2559600d57c06c133f6b48c4907823c3bc8378aa.tar.gz
use HeapAlloc() instead of malloc() around GetAdaptersAddresses
-rw-r--r--psutil/arch/windows/global.h2
-rw-r--r--psutil/arch/windows/net.c6
2 files changed, 5 insertions, 3 deletions
diff --git a/psutil/arch/windows/global.h b/psutil/arch/windows/global.h
index 2773f17a..6764dde0 100644
--- a/psutil/arch/windows/global.h
+++ b/psutil/arch/windows/global.h
@@ -19,6 +19,8 @@ extern SYSTEM_INFO PSUTIL_SYSTEM_INFO;
#define PSUTIL_WINDOWS_10 100
#define PSUTIL_WINDOWS_NEW MAXLONG
+#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
+#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
#define LO_T 1e-7
#define HI_T 429.4967296
diff --git a/psutil/arch/windows/net.c b/psutil/arch/windows/net.c
index 55008880..92887f42 100644
--- a/psutil/arch/windows/net.c
+++ b/psutil/arch/windows/net.c
@@ -19,13 +19,13 @@
static PIP_ADAPTER_ADDRESSES
psutil_get_nic_addresses() {
// allocate a 15 KB buffer to start with
- int outBufLen = 15000;
+ ULONG outBufLen = 15000;
DWORD dwRetVal = 0;
ULONG attempts = 0;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
do {
- pAddresses = (IP_ADAPTER_ADDRESSES *) malloc(outBufLen);
+ pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen);
if (pAddresses == NULL) {
PyErr_NoMemory();
return NULL;
@@ -34,7 +34,7 @@ psutil_get_nic_addresses() {
dwRetVal = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAddresses,
&outBufLen);
if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
- free(pAddresses);
+ FREE(pAddresses);
pAddresses = NULL;
}
else {