[Python-checkins] r75367 - in python/trunk: Misc/ACKS Misc/NEWS Objects/listobject.c

antoine.pitrou python-checkins at python.org
Sun Oct 11 23:03:27 CEST 2009


Author: antoine.pitrou
Date: Sun Oct 11 23:03:26 2009
New Revision: 75367

Log:
Issue #7084: Fix a (very unlikely) crash when printing a list from one
thread, and mutating it from another one.  Patch by Scott Dial.



Modified:
   python/trunk/Misc/ACKS
   python/trunk/Misc/NEWS
   python/trunk/Objects/listobject.c

Modified: python/trunk/Misc/ACKS
==============================================================================
--- python/trunk/Misc/ACKS	(original)
+++ python/trunk/Misc/ACKS	Sun Oct 11 23:03:26 2009
@@ -175,6 +175,7 @@
 Erik Demaine
 Roger Dev
 Raghuram Devarakonda
+Scott Dial
 Toby Dickenson
 Mark Dickinson
 Jack Diederich

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Oct 11 23:03:26 2009
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #7084: Fix a (very unlikely) crash when printing a list from one
+  thread, and mutating it from another one.  Patch by Scott Dial.
+
 - Issue #1571184: The Unicode database contains properties for more characters.
   The tables for code points representing numeric values, white spaces or line
   breaks are now generated from the official Unicode Character Database files,

Modified: python/trunk/Objects/listobject.c
==============================================================================
--- python/trunk/Objects/listobject.c	(original)
+++ python/trunk/Objects/listobject.c	Sun Oct 11 23:03:26 2009
@@ -319,6 +319,7 @@
 {
 	int rc;
 	Py_ssize_t i;
+	PyObject *item;
 
 	rc = Py_ReprEnter((PyObject*)op);
 	if (rc != 0) {
@@ -333,15 +334,19 @@
 	fprintf(fp, "[");
 	Py_END_ALLOW_THREADS
 	for (i = 0; i < Py_SIZE(op); i++) {
+		item = op->ob_item[i];
+		Py_INCREF(item);
 		if (i > 0) {
 			Py_BEGIN_ALLOW_THREADS
 			fprintf(fp, ", ");
 			Py_END_ALLOW_THREADS
 		}
-		if (PyObject_Print(op->ob_item[i], fp, 0) != 0) {
+		if (PyObject_Print(item, fp, 0) != 0) {
+			Py_DECREF(item);
 			Py_ReprLeave((PyObject *)op);
 			return -1;
 		}
+		Py_DECREF(item);
 	}
 	Py_BEGIN_ALLOW_THREADS
 	fprintf(fp, "]");


More information about the Python-checkins mailing list