From 04e38d94bf65b12c0fb4e5638b36140f81561233 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 3 Jul 2006 13:47:29 +0000 Subject: [PATCH] Put method-wrappers into trashcan. Fixes #927248. --- Lib/test/test_descr.py | 8 ++++++++ Misc/NEWS | 3 +++ Objects/descrobject.c | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index ed779db2eea5..4fb3b5269b54 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -3936,6 +3936,13 @@ def weakref_segfault(): o.whatever = Provoker(o) del o +def wrapper_segfault(): + # SF 927248: deeply nested wrappers could cause stack overflow + f = lambda:None + for i in xrange(1000000): + f = f.__call__ + f = None + # Fix SF #762455, segfault when sys.stdout is changed in getattr def filefault(): if verbose: @@ -4075,6 +4082,7 @@ def notimplemented(): def test_main(): weakref_segfault() # Must be first, somehow + wrapper_segfault() do_this_first() class_docstrings() lists() diff --git a/Misc/NEWS b/Misc/NEWS index a1c3cde58c40..87d5ac24da4f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.4.4c1? Core and builtins ----------------- +- Bug #927248: Recursive method-wrapper objects can now safely + be released. + - Bug #992017: A classic class that defined a __coerce__() method that returned its arguments swapped would infinitely recurse and segfault the interpreter. diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 7d523cf2014c..d12145d4bcb6 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -904,10 +904,12 @@ typedef struct { static void wrapper_dealloc(wrapperobject *wp) { - _PyObject_GC_UNTRACK(wp); + PyObject_GC_UnTrack(wp); + Py_TRASHCAN_SAFE_BEGIN(wp) Py_XDECREF(wp->descr); Py_XDECREF(wp->self); PyObject_GC_Del(wp); + Py_TRASHCAN_SAFE_END(wp) } static PyMethodDef wrapper_methods[] = { -- 2.47.3