8000 gh-115618: Remove improper Py_XDECREFs in property methods by serhiy-storchaka · Pull Request #115619 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115618: Remove improper Py_XDECREFs in property methods #115619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ def test_refleaks_in___init__(self):
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()

Expand Down
Original file line number Diff line number Diff line change
@@ -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`.
3 changes: 0 additions & 3 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
0