summaryrefslogtreecommitdiffstats
path: root/Objects/descrobject.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-02-17 19:27:42 (GMT)
committerGitHub <noreply@github.com>2022-02-17 19:27:42 (GMT)
commit9e06d03672547041239812efe4901c06da6cbd2f (patch)
tree89ed307e9b1f1de13f9551670b3ed5e1d505c62c /Objects/descrobject.c
parent98dd0aec2d0cb8971fb5363532c25041a5ba6fdc (diff)
downloadcpython-9e06d03672547041239812efe4901c06da6cbd2f.zip
cpython-9e06d03672547041239812efe4901c06da6cbd2f.tar.gz
cpython-9e06d03672547041239812efe4901c06da6cbd2f.tar.bz2
bpo-46730: Fix refleak and tighten NULL checks (GH-31389)
``PyType_GetQualName`` returns a new reference. Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r--Objects/descrobject.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 9379ad6..2d4cfb5 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1585,18 +1585,22 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
propertyobject *gs = (propertyobject *)self;
if (gs->prop_get == NULL) {
- if (gs->prop_name != NULL) {
+ PyObject *qualname = PyType_GetQualName(Py_TYPE(obj));
+ if (gs->prop_name != NULL && qualname != NULL) {
PyErr_Format(PyExc_AttributeError,
"property %R of %R object has no getter",
gs->prop_name,
- PyType_GetQualName(Py_TYPE(obj)));
+ qualname);
}
- else {
+ else if (qualname != NULL) {
PyErr_Format(PyExc_AttributeError,
"property of %R object has no getter",
- PyType_GetQualName(Py_TYPE(obj)));
+ qualname);
+ } else {
+ PyErr_SetString(PyExc_AttributeError,
+ "property has no getter");
}
-
+ Py_XDECREF(qualname);
return NULL;
}
@@ -1617,20 +1621,24 @@ property_descr_set(PyObject *self, PyObject *obj, PyObject *value)
}
if (func == NULL) {
- if (gs->prop_name != NULL && obj != NULL) {
+ PyObject *qualname = NULL;
+ if (obj != NULL) {
+ qualname = PyType_GetQualName(Py_TYPE(obj));
+ }
+ if (gs->prop_name != NULL && qualname != NULL) {
PyErr_Format(PyExc_AttributeError,
value == NULL ?
"property %R of %R object has no deleter" :
"property %R of %R object has no setter",
gs->prop_name,
- PyType_GetQualName(Py_TYPE(obj)));
+ qualname);
}
- else if (obj != NULL) {
+ else if (qualname != NULL) {
PyErr_Format(PyExc_AttributeError,
value == NULL ?
"property of %R object has no deleter" :
"property of %R object has no setter",
- PyType_GetQualName(Py_TYPE(obj)));
+ qualname);
}
else {
PyErr_SetString(PyExc_AttributeError,
@@ -1638,6 +1646,7 @@ property_descr_set(PyObject *self, PyObject *obj, PyObject *value)
"property has no deleter" :
"property has no setter");
}
+ Py_XDECREF(qualname);
return -1;
}