mirror of https://github.com/python/cpython
bpo-33930: Fix segfault with deep recursion when cleaning method objects (GH-27678)
This commit is contained in:
parent
c0ab59f7de
commit
bfc2d5a5c4
|
@ -1169,6 +1169,21 @@ class ExceptionTests(unittest.TestCase):
|
||||||
self.assertIsInstance(v, RecursionError, type(v))
|
self.assertIsInstance(v, RecursionError, type(v))
|
||||||
self.assertIn("maximum recursion depth exceeded", str(v))
|
self.assertIn("maximum recursion depth exceeded", str(v))
|
||||||
|
|
||||||
|
|
||||||
|
@cpython_only
|
||||||
|
def test_crashcan_recursion(self):
|
||||||
|
# See bpo-33930
|
||||||
|
|
||||||
|
def foo():
|
||||||
|
o = object()
|
||||||
|
for x in range(1_000_000):
|
||||||
|
# Create a big chain of method objects that will trigger
|
||||||
|
# a deep chain of calls when they need to be destructed.
|
||||||
|
o = o.__dir__
|
||||||
|
|
||||||
|
foo()
|
||||||
|
support.gc_collect()
|
||||||
|
|
||||||
@cpython_only
|
@cpython_only
|
||||||
def test_recursion_normalizing_exception(self):
|
def test_recursion_normalizing_exception(self):
|
||||||
# Issue #22898.
|
# Issue #22898.
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix segmentation fault with deep recursion when cleaning method objects.
|
||||||
|
Patch by Augusto Goulart and Pablo Galindo.
|
|
@ -160,7 +160,10 @@ PyCMethod_GetClass(PyObject *op)
|
||||||
static void
|
static void
|
||||||
meth_dealloc(PyCFunctionObject *m)
|
meth_dealloc(PyCFunctionObject *m)
|
||||||
{
|
{
|
||||||
_PyObject_GC_UNTRACK(m);
|
// The Py_TRASHCAN mechanism requires that we be able to
|
||||||
|
// call PyObject_GC_UnTrack twice on an object.
|
||||||
|
PyObject_GC_UnTrack(m);
|
||||||
|
Py_TRASHCAN_BEGIN(m, meth_dealloc);
|
||||||
if (m->m_weakreflist != NULL) {
|
if (m->m_weakreflist != NULL) {
|
||||||
PyObject_ClearWeakRefs((PyObject*) m);
|
PyObject_ClearWeakRefs((PyObject*) m);
|
||||||
}
|
}
|
||||||
|
@ -170,6 +173,7 @@ meth_dealloc(PyCFunctionObject *m)
|
||||||
Py_XDECREF(m->m_self);
|
Py_XDECREF(m->m_self);
|
||||||
Py_XDECREF(m->m_module);
|
Py_XDECREF(m->m_module);
|
||||||
PyObject_GC_Del(m);
|
PyObject_GC_Del(m);
|
||||||
|
Py_TRASHCAN_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Reference in New Issue