@@ -1112,11 +1112,13 @@ _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
11121112 attr_old = getattrs (self -> win );
11131113 if (curses_wattrset (self , attr , "addstr" ) < 0 ) {
11141114 curses_release_wstr (strtype , wstr );
1115+ Py_XDECREF (bytesobj );
11151116 return NULL ;
11161117 }
11171118 }
11181119#ifdef HAVE_NCURSESW
11191120 if (strtype == 2 ) {
1121+ assert (bytesobj == NULL );
11201122 if (use_xy ) {
11211123 rtn = mvwaddwstr (self -> win ,y ,x ,wstr );
11221124 funcname = "mvwaddwstr" ;
@@ -1130,6 +1132,7 @@ _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
11301132 else
11311133#endif
11321134 {
1135+ assert (wstr == NULL );
11331136 const char * str = PyBytes_AS_STRING (bytesobj );
11341137 if (use_xy ) {
11351138 rtn = mvwaddstr (self -> win ,y ,x ,str );
@@ -1210,6 +1213,7 @@ _curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1,
12101213 attr_old = getattrs (self -> win );
12111214 if (curses_wattrset (self , attr , "addnstr" ) < 0 ) {
12121215 curses_release_wstr (strtype , wstr );
1216+ Py_XDECREF (bytesobj );
12131217 return NULL ;
12141218 }
12151219 }
@@ -2212,6 +2216,7 @@ _curses_window_insstr_impl(PyCursesWindowObject *self, int group_left_1,
22122216 attr_old = getattrs (self -> win );
22132217 if (curses_wattrset (self , attr , "insstr" ) < 0 ) {
22142218 curses_release_wstr (strtype , wstr );
2219+ Py_XDECREF (bytesobj );
22152220 return NULL ;
22162221 }
22172222 }
0 commit comments