[Python-checkins] cpython (3.3): #18113: Objects associated to a curses.panel object with set_userptr() were
andrew.kuchling
python-checkins at python.org
Sat Jun 15 21:03:32 CEST 2013
http://hg.python.org/cpython/rev/3d75bd69e5a9
changeset: 84152:3d75bd69e5a9
branch: 3.3
parent: 84144:61a1aa69e83e
user: Andrew Kuchling <amk at amk.ca>
date: Sat Jun 15 14:04:04 2013 -0400
summary:
#18113: Objects associated to a curses.panel object with set_userptr() were leaked.
Reported by Atsuo Ishimoto.
files:
Lib/test/test_curses.py | 13 +++++++++++++
Misc/NEWS | 3 +++
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
--- a/Lib/test/test_curses.py
+++ b/Lib/test/test_curses.py
@@ -252,6 +252,18 @@
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
@@ -317,6 +329,7 @@
module_funcs(stdscr)
window_funcs(stdscr)
test_userptr_without_set(stdscr)
+ test_userptr_memory_leak(stdscr)
test_resize_term(stdscr)
test_issue6243(stdscr)
test_unget_wch(stdscr)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -78,6 +78,9 @@
the default for linking if LDSHARED is not also overriden. This restores
Distutils behavior introduced in 3.2.3 and inadvertently dropped in 3.3.0.
+- Issue #18113: Fixed a refcount leak in the curses.panel module's
+ set_userptr() method. Reported by Atsuo Ishimoto.
+
IDLE
----
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -322,6 +322,10 @@
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");
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list