summaryrefslogtreecommitdiff
path: root/Modules/selectmodule.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-02-23 21:48:57 +0000
committerGeorg Brandl <georg@python.org>2010-02-23 21:48:57 +0000
commit30cd36f426f0d8124f78865a1fb047ab9ceb3a24 (patch)
treed1626367e900560b16988d9e9b2492bc2e66d31d /Modules/selectmodule.c
parentc2a80364ed0a6b6d89f74d61f3b163ed27cb72ac (diff)
downloadcpython-30cd36f426f0d8124f78865a1fb047ab9ceb3a24.tar.gz
#6544: fix refleak in kqueue, occurring in certain error conditions.
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r--Modules/selectmodule.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index f243a1d0a2..aae08d5b81 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -1236,6 +1236,7 @@ static struct PyMemberDef kqueue_event_members[] = {
#undef KQ_OFF
static PyObject *
+
kqueue_event_repr(kqueue_event_Object *s)
{
char buf[1024];
@@ -1521,19 +1522,6 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
return NULL;
}
- if (ch != NULL && ch != Py_None) {
- it = PyObject_GetIter(ch);
- if (it == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "changelist is not iterable");
- return NULL;
- }
- nchanges = PyObject_Size(ch);
- if (nchanges < 0) {
- return NULL;
- }
- }
-
if (otimeout == Py_None || otimeout == NULL) {
ptimeoutspec = NULL;
}
@@ -1569,11 +1557,22 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
return NULL;
}
- if (nchanges) {
+ if (ch != NULL && ch != Py_None) {
+ it = PyObject_GetIter(ch);
+ if (it == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "changelist is not iterable");
+ return NULL;
+ }
+ nchanges = PyObject_Size(ch);
+ if (nchanges < 0) {
+ goto error;
+ }
+
chl = PyMem_New(struct kevent, nchanges);
if (chl == NULL) {
PyErr_NoMemory();
- return NULL;
+ goto error;
}
i = 0;
while ((ei = PyIter_Next(it)) != NULL) {
@@ -1596,7 +1595,7 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)
evl = PyMem_New(struct kevent, nevents);
if (evl == NULL) {
PyErr_NoMemory();
- return NULL;
+ goto error;
}
}