summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-10-11 21:03:26 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-10-11 21:03:26 (GMT)
commitbeaf6a02f45fe667ddcb1fbdd24f1ea7189b2105 (patch)
tree9a6492bd6a835552d3725436b1e0ce02cffa4b2c /Objects
parenta4314c2b218fb0509a24c873a22137ff229a01fd (diff)
downloadcpython-beaf6a02f45fe667ddcb1fbdd24f1ea7189b2105.zip
cpython-beaf6a02f45fe667ddcb1fbdd24f1ea7189b2105.tar.gz
cpython-beaf6a02f45fe667ddcb1fbdd24f1ea7189b2105.tar.bz2
Issue #7084: Fix a (very unlikely) crash when printing a list from one
thread, and mutating it from another one. Patch by Scott Dial.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/listobject.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 98d7e47..c5b1475 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, "]");