]> granicus.if.org Git - python/commitdiff
#6544: fix refleak in kqueue, occurring in certain error conditions.
authorGeorg Brandl <georg@python.org>
Tue, 23 Feb 2010 21:48:57 +0000 (21:48 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 23 Feb 2010 21:48:57 +0000 (21:48 +0000)
Misc/NEWS
Modules/selectmodule.c

index 8b91de8345d638223a0618c2b613e114cbcff403..dd2346be0b9ba74ef4039ce946a6b597aad6a2a2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -58,6 +58,9 @@ Library
 Extension Modules
 -----------------
 
+- Issue #6544: fix a reference leak in the kqueue implementation's error
+  handling.
+
 - Stop providing crtassem.h symbols when compiling with Visual Studio 2010, as
   msvcr100.dll is not a platform assembly anymore.
 
index f243a1d0a2b68071d26e1e6104680fee7ec94c7f..aae08d5b817142c2bb2c5db10d9c550b2c9770ed 100644 (file)
@@ -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;
                }
        }