summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2018-12-10 14:47:00 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2018-12-10 14:47:00 +0100
commit790292d3902a51800117e9343be918ec1ddecbde (patch)
treeab66f80e31c306b4cc8951beecc14523c863ae5e
parent62410eb927d20003271fb0c5d66a21bf59f38628 (diff)
downloadpsutil-790292d3902a51800117e9343be918ec1ddecbde.tar.gz
#1376 Windows: check if variable is NULL before free()ing it
-rw-r--r--HISTORY.rst2
-rw-r--r--psutil/arch/windows/process_info.c13
2 files changed, 10 insertions, 5 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 36648571..263a381f 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -21,6 +21,8 @@ XXXX-XX-XX
- 1376_: [Windows] OpenProcess() now uses PROCESS_QUERY_LIMITED_INFORMATION
access rights wherever possible, resulting in less AccessDenied exceptions
being thrown for system processes.
+- 1376_: [Windows] check if variable is NULL before free()ing it. (patch by
+ EccoTheFlintstone)
5.4.8
=====
diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c
index d83b7150..b79aeb3e 100644
--- a/psutil/arch/windows/process_info.c
+++ b/psutil/arch/windows/process_info.c
@@ -302,7 +302,8 @@ psutil_get_pids(DWORD *numberOfReturnedPIDs) {
do {
procArraySz += 1024;
- free(procArray);
+ if (procArray != NULL)
+ free(procArray);
procArrayByteSz = procArraySz * sizeof(DWORD);
procArray = malloc(procArrayByteSz);
if (procArray == NULL) {
@@ -833,7 +834,8 @@ psutil_get_cmdline(long pid) {
out:
LocalFree(szArglist);
- free(data);
+ if (data != NULL)
+ free(data);
Py_XDECREF(py_unicode);
Py_XDECREF(py_retlist);
@@ -852,7 +854,8 @@ PyObject *psutil_get_cwd(long pid) {
ret = PyUnicode_FromWideChar(data, wcslen(data));
out:
- free(data);
+ if (data != NULL)
+ free(data);
return ret;
}
@@ -873,8 +876,8 @@ PyObject *psutil_get_environ(long pid) {
ret = PyUnicode_FromWideChar(data, size / 2);
out:
- free(data);
-
+ if (data != NULL)
+ free(data);
return ret;
}