[Python-checkins] bpo-43108: Fix a reference leak in the curses module (GH-24420)

pablogsal webhook-mailer at python.org
Tue Feb 2 15:38:35 EST 2021


https://github.com/python/cpython/commit/bb739ec922c6992a2be38f9fd3c544c2cc322dde
commit: bb739ec922c6992a2be38f9fd3c544c2cc322dde
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-02-02T20:38:26Z
summary:

bpo-43108: Fix a reference leak in the curses module (GH-24420)

files:
A Misc/NEWS.d/next/Library/2021-02-02-20-23-31.bpo-43108.lqcCZ6.rst
M Modules/_cursesmodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-02-02-20-23-31.bpo-43108.lqcCZ6.rst b/Misc/NEWS.d/next/Library/2021-02-02-20-23-31.bpo-43108.lqcCZ6.rst
new file mode 100644
index 0000000000000..8e45640bceae1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-02-02-20-23-31.bpo-43108.lqcCZ6.rst
@@ -0,0 +1 @@
+Fixed a reference leak in the :mod:`curses` module. Patch by Pablo Galindo
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 4fcedc5fc4820..3df9f506052d3 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -388,6 +388,7 @@ PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,
         *bytes = obj;
         /* check for embedded null bytes */
         if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
+            Py_DECREF(obj);
             return 0;
         }
         return 1;
@@ -828,8 +829,9 @@ _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
 #else
     strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
 #endif
-    if (strtype == 0)
+    if (strtype == 0) {
         return NULL;
+    }
     if (use_attr) {
         attr_old = getattrs(self->win);
         (void)wattrset(self->win,attr);



More information about the Python-checkins mailing list