Commit 155aad17 authored by Martin v. Löwis's avatar Martin v. Löwis

Patch #486743: remove bad INCREF, propagate exception in append_objects.

parent 8b6bd42e
...@@ -701,17 +701,19 @@ static char gc_get_objects__doc__[] = ...@@ -701,17 +701,19 @@ static char gc_get_objects__doc__[] =
; ;
/* appending objects in a GC list to a Python list */ /* appending objects in a GC list to a Python list */
static void static int
append_objects(PyObject *py_list, PyGC_Head *gc_list) append_objects(PyObject *py_list, PyGC_Head *gc_list)
{ {
PyGC_Head *gc; PyGC_Head *gc;
for (gc = gc_list->gc.gc_next; gc != gc_list; gc = gc->gc.gc_next) { for (gc = gc_list->gc.gc_next; gc != gc_list; gc = gc->gc.gc_next) {
PyObject *op = FROM_GC(gc); PyObject *op = FROM_GC(gc);
if (op != py_list) { if (op != py_list) {
Py_INCREF(op); if (PyList_Append(py_list, op)) {
PyList_Append(py_list, op); return -1; /* exception */
}
} }
} }
return 0;
} }
static PyObject * static PyObject *
...@@ -722,9 +724,12 @@ gc_get_objects(PyObject *self, PyObject *args) ...@@ -722,9 +724,12 @@ gc_get_objects(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, ":get_objects")) /* check no args */ if (!PyArg_ParseTuple(args, ":get_objects")) /* check no args */
return NULL; return NULL;
result = PyList_New(0); result = PyList_New(0);
append_objects(result, &_PyGC_generation0); if (append_objects(result, &_PyGC_generation0) ||
append_objects(result, &generation1); append_objects(result, &generation1) ||
append_objects(result, &generation2); append_objects(result, &generation2)) {
Py_DECREF(result);
return NULL;
}
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment