diff options
author | Andrew Kuchling <amk@amk.ca> | 2013-06-15 17:53:10 (GMT) |
---|---|---|
committer | Andrew Kuchling <amk@amk.ca> | 2013-06-15 17:53:10 (GMT) |
commit | a49dcc51b8fcdcdf06f1e5b136b5835d754a0d05 (patch) | |
tree | 13a26ea1ca2bf4cfa0da3882c8289596be04498b | |
parent | 03512c18cbf75f0a6c3703bf0141761841634c95 (diff) | |
download | cpython-a49dcc51b8fcdcdf06f1e5b136b5835d754a0d05.zip cpython-a49dcc51b8fcdcdf06f1e5b136b5835d754a0d05.tar.gz cpython-a49dcc51b8fcdcdf06f1e5b136b5835d754a0d05.tar.bz2 |
#18113: Objects associated to a curses.panel object with set_userptr() were leaked.
Reported by Atsuo Ishimoto.
-rw-r--r-- | Lib/test/test_curses.py | 13 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_curses_panel.c | 4 |
3 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index fa0d469..387a185 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -250,6 +250,18 @@ def test_userptr_without_set(stdscr): except curses.panel.error: pass +def test_userptr_memory_leak(stdscr): + w = curses.newwin(10, 10) + p = curses.panel.new_panel(w) + obj = object() + nrefs = sys.getrefcount(obj) + for i in range(100): + p.set_userptr(obj) + + p.set_userptr(None) + if sys.getrefcount(obj) != nrefs: + raise RuntimeError, "set_userptr leaked references" + def test_resize_term(stdscr): if hasattr(curses, 'resizeterm'): lines, cols = curses.LINES, curses.COLS @@ -268,6 +280,7 @@ def main(stdscr): module_funcs(stdscr) window_funcs(stdscr) test_userptr_without_set(stdscr) + test_userptr_memory_leak(stdscr) test_resize_term(stdscr) test_issue6243(stdscr) finally: @@ -40,6 +40,9 @@ Library the default for linking if LDSHARED is not also overriden. This restores Distutils behavior introduced in 2.7.3 and inadvertently dropped in 2.7.4. +- Issue #18113: Fixed a refcount leak in the curses.panel module's + set_userptr() method. Reported by Atsuo Ishimoto. + Build ----- diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c index 04a0a28..dd231e7 100644 --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -293,6 +293,10 @@ PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args) static PyObject * PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj) { + PyObject *oldobj; + PyCursesInitialised; + oldobj = (PyObject *) panel_userptr(self->pan); + Py_XDECREF(oldobj); Py_INCREF(obj); return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj), "set_panel_userptr"); |