summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-02-17 21:18:30 (GMT)
committerGitHub <noreply@github.com>2024-02-17 21:18:30 (GMT)
commit090dd21ab9379d6a2a6923d6cbab697355fb7165 (patch)
tree0979b9e8e3b11a590902c5745fe817943a888c33
parentaba37d451fabb44a7f478958ba117ae5b6ea54c0 (diff)
downloadcpython-090dd21ab9379d6a2a6923d6cbab697355fb7165.zip
cpython-090dd21ab9379d6a2a6923d6cbab697355fb7165.tar.gz
cpython-090dd21ab9379d6a2a6923d6cbab697355fb7165.tar.bz2
gh-115618: Remove improper Py_XDECREFs in property methods (GH-115619)
-rw-r--r--Lib/test/test_property.py18
-rw-r--r--Misc/NEWS.d/next/Library/2024-02-17-18-47-12.gh-issue-115618.napiNp.rst3
-rw-r--r--Objects/descrobject.c3
3 files changed, 21 insertions, 3 deletions
diff --git a/Lib/test/test_property.py b/Lib/test/test_property.py
index 8ace9fd..ad5ab5a 100644
--- a/Lib/test/test_property.py
+++ b/Lib/test/test_property.py
@@ -183,6 +183,24 @@ class PropertyTests(unittest.TestCase):
fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+ @support.refcount_test
+ def test_gh_115618(self):
+ # Py_XDECREF() was improperly called for None argument
+ # in property methods.
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ prop = property()
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ prop = prop.getter(None)
+ self.assertIsNone(prop.fget)
+ for i in range(100):
+ prop = prop.setter(None)
+ self.assertIsNone(prop.fset)
+ for i in range(100):
+ prop = prop.deleter(None)
+ self.assertIsNone(prop.fdel)
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
def test_property_set_name_incorrect_args(self):
p = property()
diff --git a/Misc/NEWS.d/next/Library/2024-02-17-18-47-12.gh-issue-115618.napiNp.rst b/Misc/NEWS.d/next/Library/2024-02-17-18-47-12.gh-issue-115618.napiNp.rst
new file mode 100644
index 0000000..cb4b147
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-02-17-18-47-12.gh-issue-115618.napiNp.rst
@@ -0,0 +1,3 @@
+Fix improper decreasing the reference count for ``None`` argument in
+:class:`property` methods :meth:`~property.getter`, :meth:`~property.setter`
+and :meth:`~property.deleter`.
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 805de29..c4cd51b 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1730,15 +1730,12 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del)
return NULL;
if (get == NULL || get == Py_None) {
- Py_XDECREF(get);
get = pold->prop_get ? pold->prop_get : Py_None;
}
if (set == NULL || set == Py_None) {
- Py_XDECREF(set);
set = pold->prop_set ? pold->prop_set : Py_None;
}
if (del == NULL || del == Py_None) {
- Py_XDECREF(del);
del = pold->prop_del ? pold->prop_del : Py_None;
}
if (pold->getter_doc && get != Py_None) {