Skip to content

Commit

Permalink
#1376 Windows: check if variable is NULL before free()ing it
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 10, 2018
1 parent 62410eb commit 790292d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand Down
13 changes: 8 additions & 5 deletions psutil/arch/windows/process_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 790292d

Please sign in to comment.