@@ -3137,6 +3137,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
3137
3137
PyTypeObject * metatype = Py_TYPE (type );
3138
3138
PyObject * meta_attribute , * attribute ;
3139
3139
descrgetfunc meta_get ;
3140
+ PyObject * res ;
3140
3141
3141
3142
if (!PyUnicode_Check (name )) {
3142
3143
PyErr_Format (PyExc_TypeError ,
@@ -3158,36 +3159,40 @@ type_getattro(PyTypeObject *type, PyObject *name)
3158
3159
meta_attribute = _PyType_Lookup (metatype , name );
3159
3160
3160
3161
if (meta_attribute != NULL ) {
3162
+ Py_INCREF (meta_attribute );
3161
3163
meta_get = Py_TYPE (meta_attribute )-> tp_descr_get ;
3162
3164
3163
3165
if (meta_get != NULL && PyDescr_IsData (meta_attribute )) {
3164
3166
/* Data descriptors implement tp_descr_set to intercept
3165
3167
* writes. Assume the attribute is not overridden in
3166
3168
* type's tp_dict (and bases): call the descriptor now.
3167
3169
*/
3168
- return meta_get (meta_attribute , (PyObject * )type ,
3169
- (PyObject * )metatype );
3170
+ res = meta_get (meta_attribute , (PyObject * )type ,
3171
+ (PyObject * )metatype );
3172
+ Py_DECREF (meta_attribute );
3173
+ return res ;
3170
3174
}
3171
- Py_INCREF (meta_attribute );
3172
3175
}
3173
3176
3174
3177
/* No data descriptor found on metatype. Look in tp_dict of this
3175
3178
* type and its bases */
3176
3179
attribute = _PyType_Lookup (type , name );
3177
3180
if (attribute != NULL ) {
3178
3181
/* Implement descriptor functionality, if any */
3182
+ Py_INCREF (attribute );
3179
3183
descrgetfunc local_get = Py_TYPE (attribute )-> tp_descr_get ;
3180
3184
3181
3185
Py_XDECREF (meta_attribute );
3182
3186
3183
3187
if (local_get != NULL ) {
3184
3188
/* NULL 2nd argument indicates the descriptor was
3185
3189
* found on the target object itself (or a base) */
3186
- return local_get (attribute , (PyObject * )NULL ,
3187
- (PyObject * )type );
3190
+ res = local_get (attribute , (PyObject * )NULL ,
3191
+ (PyObject * )type );
3192
+ Py_DECREF (attribute );
3193
+ return res ;
3188
3194
}
3189
3195
3190
- Py_INCREF (attribute );
3191
3196
return attribute ;
3192
3197
}
3193
3198
0 commit comments