[3.8] bpo-36589: Fix the error handling in curses.update_lines_cols()… · python/cpython@187785e
@@ -3757,15 +3757,18 @@ update_lines_cols(void)
37573757}
3758375837593759/*[clinic input]
3760-_curses.update_lines_cols -> int
3760+_curses.update_lines_cols
3761376137623762[clinic start generated code]*/
376337633764-static int
3764+static PyObject *
37653765_curses_update_lines_cols_impl(PyObject *module)
3766-/*[clinic end generated code: output=0345e7f072ea711a input=3a87760f7d5197f0]*/
3766+/*[clinic end generated code: output=423f2b1e63ed0f75 input=5f065ab7a28a5d90]*/
37673767{
3768-return update_lines_cols();
3768+if (!update_lines_cols()) {
3769+return NULL;
3770+ }
3771+Py_RETURN_NONE;
37693772}
3770377337713774#endif
@@ -3849,8 +3852,10 @@ _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
38493852result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");
38503853if (!result)
38513854return NULL;
3852-if (!update_lines_cols())
3855+if (!update_lines_cols()) {
3856+Py_DECREF(result);
38533857return NULL;
3858+ }
38543859return result;
38553860}
38563861@@ -3886,8 +3891,10 @@ _curses_resize_term_impl(PyObject *module, int nlines, int ncols)
38863891result = PyCursesCheckERR(resize_term(nlines, ncols), "resize_term");
38873892if (!result)
38883893return NULL;
3889-if (!update_lines_cols())
3894+if (!update_lines_cols()) {
3895+Py_DECREF(result);
38903896return NULL;
3897+ }
38913898return result;
38923899}
38933900#endif /* HAVE_CURSES_RESIZE_TERM */
@@ -3958,12 +3965,18 @@ _curses_start_color_impl(PyObject *module)
39583965c = PyLong_FromLong((long) COLORS);
39593966if (c == NULL)
39603967return NULL;
3961-PyDict_SetItemString(ModDict, "COLORS", c);
3968+if (PyDict_SetItemString(ModDict, "COLORS", c) < 0) {
3969+Py_DECREF(c);
3970+return NULL;
3971+ }
39623972Py_DECREF(c);
39633973cp = PyLong_FromLong((long) COLOR_PAIRS);
39643974if (cp == NULL)
39653975return NULL;
3966-PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
3976+if (PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp) < 0) {
3977+Py_DECREF(cp);
3978+return NULL;
3979+ }
39673980Py_DECREF(cp);
39683981Py_RETURN_NONE;
39693982 } else {