]> granicus.if.org Git - python/commitdiff
Issue #3299: fix curses.panel.new_panel() error handler, replace PyObject_DEL()
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 3 Mar 2010 21:53:41 +0000 (21:53 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 3 Mar 2010 21:53:41 +0000 (21:53 +0000)
by Py_DECREF() to avoid a crash in pydebug mode.

Use po->wo==NULL to detect than the panel is in the lop list or not.

Modules/_curses_panel.c

index 6831473b06f5a30d37ed3b8783e7c1601c38a521..74e6bfa2b17e3ea56d084eb964b2aa38c9e385d3 100644 (file)
@@ -178,12 +178,13 @@ PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo)
     po = PyObject_NEW(PyCursesPanelObject, &PyCursesPanel_Type);
     if (po == NULL) return NULL;
     po->pan = pan;
-    po->wo = wo;
-    Py_INCREF(wo);
     if (insert_lop(po) < 0) {
-       PyObject_DEL(po);
+       po->wo = NULL;
+       Py_DECREF(po);
        return NULL;
     }
+    po->wo = wo;
+    Py_INCREF(wo);
     return (PyObject *)po;
 }
 
@@ -191,8 +192,10 @@ static void
 PyCursesPanel_Dealloc(PyCursesPanelObject *po)
 {
     (void)del_panel(po->pan);
-    Py_DECREF(po->wo);
-    remove_lop(po);
+    if (po->wo != NULL) {
+       Py_DECREF(po->wo);
+       remove_lop(po);
+    }
     PyObject_DEL(po);
 }