Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a2a902

Browse files
committed
Merge with 3.3
2 parents f15a59f + 53e5ea7 commit 8a2a902

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

Lib/test/test_curses.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ def test_userptr_without_set(stdscr):
252252
except curses.panel.error:
253253
pass
254254

255+
def test_userptr_memory_leak(stdscr):
256+
w = curses.newwin(10, 10)
257+
p = curses.panel.new_panel(w)
258+
obj = object()
259+
nrefs = sys.getrefcount(obj)
260+
for i in range(100):
261+
p.set_userptr(obj)
262+
263+
p.set_userptr(None)
264+
if sys.getrefcount(obj) != nrefs:
265+
raise RuntimeError("set_userptr leaked references")
266+
255267
def test_resize_term(stdscr):
256268
if hasattr(curses, 'resizeterm'):
257269
lines, cols = curses.LINES, curses.COLS
@@ -317,6 +329,7 @@ def main(stdscr):
317329
module_funcs(stdscr)
318330
window_funcs(stdscr)
319331
test_userptr_without_set(stdscr)
332+
test_userptr_memory_leak(stdscr)
320333
test_resize_term(stdscr)
321334
test_issue6243(stdscr)
322335
test_unget_wch(stdscr)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ Library
383383
the default for linking if LDSHARED is not also overriden. This restores
384384
Distutils behavior introduced in 3.2.3 and inadvertently dropped in 3.3.0.
385385

386+
- Issue #18113: Fixed a refcount leak in the curses.panel module's
387+
set_userptr() method. Reported by Atsuo Ishimoto.
388+
386389
- Implement PEP 443 "Single-dispatch generic functions".
387390

388391
- Implement PEP 435 "Adding an Enum type to the Python standard library".

Modules/_curses_panel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
322322
static PyObject *
323323
PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj)
324324
{
325+
PyObject *oldobj;
326+
PyCursesInitialised;
327+
oldobj = (PyObject *) panel_userptr(self->pan);
328+
Py_XDECREF(oldobj);
325329
Py_INCREF(obj);
326330
return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj),
327331
"set_panel_userptr");

0 commit comments

Comments
 (0)