Skip to content

Commit 090dd21

Browse files
gh-115618: Remove improper Py_XDECREFs in property methods (GH-115619)
1 parent aba37d4 commit 090dd21

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Lib/test/test_property.py

+18
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ def test_refleaks_in___init__(self):
183183
fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
184184
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
185185

186+
@support.refcount_test
187+
def test_gh_115618(self):
188+
# Py_XDECREF() was improperly called for None argument
189+
# in property methods.
190+
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
191+
prop = property()
192+
refs_before = gettotalrefcount()
193+
for i in range(100):
194+
prop = prop.getter(None)
195+
self.assertIsNone(prop.fget)
196+
for i in range(100):
197+
prop = prop.setter(None)
198+
self.assertIsNone(prop.fset)
199+
for i in range(100):
200+
prop = prop.deleter(None)
201+
self.assertIsNone(prop.fdel)
202+
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
203+
186204
def test_property_set_name_incorrect_args(self):
187205
p = property()
188206

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix improper decreasing the reference count for ``None`` argument in
2+
:class:`property` methods :meth:`~property.getter`, :meth:`~property.setter`
3+
and :meth:`~property.deleter`.

Objects/descrobject.c

-3
Original file line numberDiff line numberDiff line change
@@ -1730,15 +1730,12 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
17301730
return NULL;
17311731

17321732
if (get == NULL || get == Py_None) {
1733-
Py_XDECREF(get);
17341733
get = pold->prop_get ? pold->prop_get : Py_None;
17351734
}
17361735
if (set == NULL || set == Py_None) {
1737-
Py_XDECREF(set);
17381736
set = pold->prop_set ? pold->prop_set : Py_None;
17391737
}
17401738
if (del == NULL || del == Py_None) {
1741-
Py_XDECREF(del);
17421739
del = pold->prop_del ? pold->prop_del : Py_None;
17431740
}
17441741
if (pold->getter_doc && get != Py_None) {

0 commit comments

Comments
 (0)