summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-09-22 19:46:07 +0200
committerGitHub <noreply@github.com>2016-09-22 19:46:07 +0200
commit95aea67adb89f7207322ceb3bf91af79e7fa77e9 (patch)
tree3a24bfa36f63948aa5f2a5b2d8d3058389db5d75
parentc913480621da83b9cc78ade2217a81490142a604 (diff)
parentf6269a6321a41bf6e9490425e1549e24cce225c7 (diff)
downloadpsutil-95aea67adb89f7207322ceb3bf91af79e7fa77e9.tar.gz
Merge pull request #825 from hardikar/master
Fix possible double close and use of unopened socket
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_psutil_linux.c8
-rw-r--r--psutil/arch/bsd/freebsd.c2
3 files changed, 6 insertions, 5 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index f7c0b804..57474f8e 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -83,6 +83,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #797: [Linux] net_if_stats() may raise OSError for certain NIC cards.
- #813: Process.as_dict() should ignore extraneous attribute names which gets
attached to the Process instance.
+- #825: Fix possible double close and use of unopened socket
4.1.0 - 2016-03-12
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 19fd14b9..5f6b6616 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -402,7 +402,7 @@ psutil_proc_cpu_affinity_set(PyObject *self, PyObject *args) {
#else
long value = PyInt_AsLong(item);
#endif
- if (value == -1 && PyErr_Occurred())
+ if (value == -1 || PyErr_Occurred())
goto error;
CPU_SET(value, &cpu_set);
}
@@ -536,17 +536,17 @@ psutil_net_if_stats(PyObject* self, PyObject* args) {
}
}
- close(sock);
py_retlist = Py_BuildValue("[Oiii]", py_is_up, duplex, speed, mtu);
if (!py_retlist)
goto error;
+ close(sock);
Py_DECREF(py_is_up);
return py_retlist;
error:
- Py_XDECREF(py_is_up);
- if (sock != 0)
+ if (sock != -1)
close(sock);
+ Py_XDECREF(py_is_up);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
diff --git a/psutil/arch/bsd/freebsd.c b/psutil/arch/bsd/freebsd.c
index d335a7ad..f7e15f75 100644
--- a/psutil/arch/bsd/freebsd.c
+++ b/psutil/arch/bsd/freebsd.c
@@ -971,7 +971,7 @@ psutil_proc_cpu_affinity_set(PyObject *self, PyObject *args) {
#else
long value = PyInt_AsLong(item);
#endif
- if (value == -1 && PyErr_Occurred())
+ if (value == -1 || PyErr_Occurred())
goto error;
CPU_SET(value, &cpu_set);
}