@@ -437,11 +437,11 @@ PyCursesPanel_Clear(PyObject *op)
437437 PyCursesPanelObject * self = _PyCursesPanelObject_CAST (op );
438438 PyObject * extra = (PyObject * )panel_userptr (self -> pan );
439439 if (extra != NULL ) {
440- Py_DECREF (extra );
441440 if (set_panel_userptr (self -> pan , NULL ) == ERR ) {
442441 curses_panel_panel_set_error (self , "set_panel_userptr" , NULL );
443442 return -1 ;
444443 }
444+ Py_DECREF (extra );
445445 }
446446 // self->wo should not be cleared because an associated WINDOW may exist
447447 return 0 ;
@@ -454,20 +454,21 @@ PyCursesPanel_Dealloc(PyObject *self)
454454 PyObject_GC_UnTrack (self );
455455
456456 PyCursesPanelObject * po = _PyCursesPanelObject_CAST (self );
457- if (PyCursesPanel_Clear (self ) < 0 ) {
457+ PyObject * extra = (PyObject * )panel_userptr (po -> pan );
458+ if (extra != NULL && set_panel_userptr (po -> pan , NULL ) == ERR ) {
459+ curses_panel_panel_set_error (po , "set_panel_userptr" , "__del__" );
460+ PyErr_FormatUnraisable ("Exception ignored in PyCursesPanel_Dealloc()" );
461+ }
462+ if (po -> wo != NULL && remove_lop (po ) < 0 ) {
463+ PyErr_SetString (PyExc_RuntimeError , "__del__: no panel object to delete" );
458464 PyErr_FormatUnraisable ("Exception ignored in PyCursesPanel_Dealloc()" );
459465 }
460466 if (del_panel (po -> pan ) == ERR && !PyErr_Occurred ()) {
461467 curses_panel_panel_set_error (po , "del_panel" , "__del__" );
462468 PyErr_FormatUnraisable ("Exception ignored in PyCursesPanel_Dealloc()" );
463469 }
464- if (po -> wo != NULL ) {
465- Py_DECREF (po -> wo );
466- if (remove_lop (po ) < 0 ) {
467- PyErr_SetString (PyExc_RuntimeError , "__del__: no panel object to delete" );
468- PyErr_FormatUnraisable ("Exception ignored in PyCursesPanel_Dealloc()" );
469- }
470- }
470+ Py_XDECREF (extra );
471+ Py_XDECREF (po -> wo );
471472 tp -> tp_free (po );
472473 Py_DECREF (tp );
473474}
0 commit comments