Skip to content

Commit

Permalink
add some checks for PyList_New() which were missing
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 13, 2015
1 parent 7dfa88d commit 5feb936
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions psutil/_psutil_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,9 +1506,9 @@ psutil_net_io_counters(PyObject *self, PyObject *args)
size_t len;
PyObject *py_retdict = PyDict_New();
PyObject *py_ifc_info = NULL;

if (py_retdict == NULL)
return NULL;

mib[0] = CTL_NET; // networking subsystem
mib[1] = PF_ROUTE; // type of information
mib[2] = 0; // protocol (IPPROTO_xxx)
Expand Down Expand Up @@ -1597,9 +1597,9 @@ psutil_disk_io_counters(PyObject *self, PyObject *args)

PyObject *py_retdict = PyDict_New();
PyObject *py_disk_info = NULL;

if (py_retdict == NULL)
return NULL;

if (devstat_checkversion(NULL) < 0) {
PyErr_Format(PyExc_RuntimeError, "devstat_checkversion() failed");
goto error;
Expand Down Expand Up @@ -2038,9 +2038,10 @@ psutil_net_connections(PyObject* self, PyObject* args)
{
PyObject *py_retlist = PyList_New(0);

if (py_retlist == NULL)
return NULL;
if (psutil_populate_xfiles() != 1)
goto error;

if (psutil_gather_inet(IPPROTO_TCP, py_retlist) == 0)
goto error;
if (psutil_gather_inet(IPPROTO_UDP, py_retlist) == 0)
Expand Down
3 changes: 2 additions & 1 deletion psutil/_psutil_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ psutil_net_if_addrs(PyObject* self, PyObject* args)
PyObject *py_netmask = NULL;
PyObject *py_broadcast = NULL;


if (py_retlist == NULL)
return NULL
if (getifaddrs(&ifaddr) == -1) {
PyErr_SetFromErrno(PyExc_OSError);
goto error;
Expand Down
2 changes: 2 additions & 0 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,8 @@ psutil_net_if_addrs(PyObject *self, PyObject *args)
PyObject *py_address = NULL;
PyObject *py_mac_address = NULL;

if (py_retlist == NULL)
return NULL;

// allocate a 15 KB buffer to start with
outBufLen = 15000;
Expand Down

0 comments on commit 5feb936

Please sign in to comment.