[Python-checkins] r78386 - in python/trunk: Misc/NEWS Modules/selectmodule.c

georg.brandl python-checkins at python.org
Tue Feb 23 22:48:57 CET 2010


Author: georg.brandl
Date: Tue Feb 23 22:48:57 2010
New Revision: 78386

Log:
#6544: fix refleak in kqueue, occurring in certain error conditions.

Modified:
   python/trunk/Misc/NEWS
   python/trunk/Modules/selectmodule.c

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Feb 23 22:48:57 2010
@@ -58,6 +58,9 @@
 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.
 

Modified: python/trunk/Modules/selectmodule.c
==============================================================================
--- python/trunk/Modules/selectmodule.c	(original)
+++ python/trunk/Modules/selectmodule.c	Tue Feb 23 22:48:57 2010
@@ -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;
 		}
 	}
 


More information about the Python-checkins mailing list