@@ -6090,7 +6090,7 @@ static void
6090
6090
heapctypesubclasswithfinalizer_finalize (PyObject * self )
6091
6091
{
6092
6092
PyObject * error_type , * error_value , * error_traceback , * m ;
6093
- PyObject * oldtype = NULL , * newtype = NULL ;
6093
+ PyObject * oldtype = NULL , * newtype = NULL , * refcnt = NULL ;
6094
6094
6095
6095
/* Save the current exception, if any. */
6096
6096
PyErr_Fetch (& error_type , & error_value , & error_traceback );
@@ -6108,18 +6108,26 @@ heapctypesubclasswithfinalizer_finalize(PyObject *self)
6108
6108
if (PyObject_SetAttrString (self , "__class__" , newtype ) < 0 ) {
6109
6109
goto cleanup_finalize ;
6110
6110
}
6111
- if ( PyObject_SetAttrString (
6112
- oldtype , "refcnt_in_del" , PyLong_FromSsize_t ( Py_REFCNT ( oldtype ))) < 0 ) {
6111
+ refcnt = PyLong_FromSsize_t ( Py_REFCNT ( oldtype ));
6112
+ if ( refcnt == NULL ) {
6113
6113
goto cleanup_finalize ;
6114
6114
}
6115
- if (PyObject_SetAttrString (
6116
- newtype , "refcnt_in_del" , PyLong_FromSsize_t (Py_REFCNT (newtype ))) < 0 ) {
6115
+ if (PyObject_SetAttrString (oldtype , "refcnt_in_del" , refcnt ) < 0 ) {
6116
+ goto cleanup_finalize ;
6117
+ }
6118
+ Py_DECREF (refcnt );
6119
+ refcnt = PyLong_FromSsize_t (Py_REFCNT (newtype ));
6120
+ if (refcnt == NULL ) {
6121
+ goto cleanup_finalize ;
6122
+ }
6123
+ if (PyObject_SetAttrString (newtype , "refcnt_in_del" , refcnt ) < 0 ) {
6117
6124
goto cleanup_finalize ;
6118
6125
}
6119
6126
6120
6127
cleanup_finalize :
6121
6128
Py_XDECREF (oldtype );
6122
6129
Py_XDECREF (newtype );
6130
+ Py_XDECREF (refcnt );
6123
6131
6124
6132
/* Restore the saved exception. */
6125
6133
PyErr_Restore (error_type , error_value , error_traceback );
0 commit comments