diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-04-01 09:48:27 +0300 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2021-04-01 09:48:27 +0300 |
commit | 1231fa858e3872145b9cde9b533eb462cadaba7f (patch) | |
tree | e7f1f01128aa97a7e7f28dfbb5f6e99a02199008 | |
parent | fix needed for testing (diff) | |
download | pypy-1231fa858e3872145b9cde9b533eb462cadaba7f.tar.gz pypy-1231fa858e3872145b9cde9b533eb462cadaba7f.tar.bz2 pypy-1231fa858e3872145b9cde9b533eb462cadaba7f.zip |
fix memory leak
-rw-r--r-- | pypy/module/_minimal_curses/interp_curses.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/pypy/module/_minimal_curses/interp_curses.py b/pypy/module/_minimal_curses/interp_curses.py index 3c5a6d44a7..e4aa4362b4 100644 --- a/pypy/module/_minimal_curses/interp_curses.py +++ b/pypy/module/_minimal_curses/interp_curses.py @@ -37,22 +37,24 @@ def setupterm(space, w_termname=None, fd=-1): termname_err = "'%s'" % termname p_errret = lltype.malloc(rffi.INTP.TO, 1, flavor='raw') - with rffi.scoped_str2charp(termname) as ll_term: - _fd = rffi.cast(rffi.INT, _fd) - errval = fficurses.setupterm(ll_term, _fd, p_errret) - - if errval == -1: - errret = widen(p_errret[0]) - if errret == 0: - msg_ext = 'could not find terminal' - elif errret == -1: - msg_ext = 'could not find termininfo database' - else: - msg_ext = 'unknown error' - msg = ("setupterm(%s, %d) failed (err=%d): %s" % - (termname_err, fd, errret, msg_ext)) - raise curses_error(space, msg) - + try: + with rffi.scoped_str2charp(termname) as ll_term: + _fd = rffi.cast(rffi.INT, _fd) + errval = fficurses.setupterm(ll_term, _fd, p_errret) + + if errval == -1: + errret = widen(p_errret[0]) + if errret == 0: + msg_ext = 'could not find terminal' + elif errret == -1: + msg_ext = 'could not find termininfo database' + else: + msg_ext = 'unknown error' + msg = ("setupterm(%s, %d) failed (err=%d): %s" % + (termname_err, fd, errret, msg_ext)) + raise curses_error(space, msg) + finally: + llytpe.free(p_errret, flavor='raw') space.fromcache(ModuleInfo).setupterm_called = True @unwrap_spec(capname='text') |