From beaf6a02f45fe667ddcb1fbdd24f1ea7189b2105 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 11 Oct 2009 21:03:26 +0000 Subject: [PATCH] Issue #7084: Fix a (very unlikely) crash when printing a list from one thread, and mutating it from another one. Patch by Scott Dial. --- Misc/ACKS | 1 + Misc/NEWS | 3 +++ Objects/listobject.c | 7 ++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Misc/ACKS b/Misc/ACKS index 6383a46a3ab..c8f80e6c243 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -175,6 +175,7 @@ Arnaud Delobelle Erik Demaine Roger Dev Raghuram Devarakonda +Scott Dial Toby Dickenson Mark Dickinson Jack Diederich diff --git a/Misc/NEWS b/Misc/NEWS index 42a8cd9ba77..9fc3edc350f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1 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, diff --git a/Objects/listobject.c b/Objects/listobject.c index 98d7e473549..c5b14758029 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -319,6 +319,7 @@ list_print(PyListObject *op, FILE *fp, int flags) { int rc; Py_ssize_t i; + PyObject *item; rc = Py_ReprEnter((PyObject*)op); if (rc != 0) { @@ -333,15 +334,19 @@ list_print(PyListObject *op, FILE *fp, int flags) 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, "]");