Mercurial > cpython-lru_cache-weakref
diff Modules/selectmodule.c @ 59080:ea68d75529b1 legacy-trunk
#6544: fix refleak in kqueue, occurring in certain error conditions.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 23 Feb 2010 21:48:57 +0000 |
| parents | ebd061838fb1 |
| children | be044b8c343a |
line wrap: on
line diff
--- a/Modules/selectmodule.c Tue Feb 23 21:33:17 2010 +0000 +++ b/Modules/selectmodule.c Tue Feb 23 21:48:57 2010 +0000 @@ -1236,6 +1236,7 @@ #undef KQ_OFF static PyObject * + kqueue_event_repr(kqueue_event_Object *s) { char buf[1024]; @@ -1521,19 +1522,6 @@ 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 @@ 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 @@ evl = PyMem_New(struct kevent, nevents); if (evl == NULL) { PyErr_NoMemory(); - return NULL; + goto error; } }
