@@ -6304,7 +6304,7 @@ static void
6304
6304
heapctypesubclasswithfinalizer_finalize (PyObject * self )
6305
6305
{
6306
6306
PyObject * error_type , * error_value , * error_traceback , * m ;
6307
- PyObject * oldtype = NULL , * newtype = NULL ;
6307
+ PyObject * oldtype = NULL , * newtype = NULL , * refcnt = NULL ;
6308
6308
6309
6309
/* Save the current exception, if any. */
6310
6310
PyErr_Fetch (& error_type , & error_value , & error_traceback );
@@ -6322,18 +6322,26 @@ heapctypesubclasswithfinalizer_finalize(PyObject *self)
6322
6322
if (PyObject_SetAttrString (self , "__class__" , newtype ) < 0 ) {
6323
6323
goto cleanup_finalize ;
6324
6324
}
6325
- if ( PyObject_SetAttrString (
6326
- oldtype , "refcnt_in_del" , PyLong_FromSsize_t ( Py_REFCNT ( oldtype ))) < 0 ) {
6325
+ refcnt = PyLong_FromSsize_t ( Py_REFCNT ( oldtype ));
6326
+ if ( refcnt == NULL ) {
6327
6327
goto cleanup_finalize ;
6328
6328
}
6329
- if (PyObject_SetAttrString (
6330
- newtype , "refcnt_in_del" , PyLong_FromSsize_t (Py_REFCNT (newtype ))) < 0 ) {
6329
+ if (PyObject_SetAttrString (oldtype , "refcnt_in_del" , refcnt ) < 0 ) {
6330
+ goto cleanup_finalize ;
6331
+ }
6332
+ Py_DECREF (refcnt );
6333
+ refcnt = PyLong_FromSsize_t (Py_REFCNT (newtype ));
6334
+ if (refcnt == NULL ) {
6335
+ goto cleanup_finalize ;
6336
+ }
6337
+ if (PyObject_SetAttrString (newtype , "refcnt_in_del" , refcnt ) < 0 ) {
6331
6338
goto cleanup_finalize ;
6332
6339
}
6333
6340
6334
6341
cleanup_finalize :
6335
6342
Py_XDECREF (oldtype );
6336
6343
Py_XDECREF (newtype );
6344
+ Py_XDECREF (refcnt );
6337
6345
6338
6346
/* Restore the saved exception. */
6339
6347
PyErr_Restore (error_type , error_value , error_traceback );
0 commit comments