tFix a memory leak on TUI window resize - sacc - sacc(omys), simple console gopher client (mirror) HTML git clone https://git.parazyd.org/sacc DIR Log DIR Files DIR Refs DIR LICENSE --- DIR commit 6582965f7a534eb82339208980582fcb661fe7c3 DIR parent 17674fcc4257afa53e81fdeab49b21f0f57528c7 HTML Author: Quentin Rameau <quinq@fifth.space> Date: Sun, 21 Mar 2021 16:15:55 +0100 Fix a memory leak on TUI window resize Memory is allocated by setupterm, which is called on window resizing for setting new values for lines and cols. Thanks to Hiltjo for spotting that! Diffstat: M ui_ti.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) --- DIR diff --git a/ui_ti.c b/ui_ti.c t@@ -13,10 +13,19 @@ #define C(c) #c #define S(c) C(c) +/* ncurses doesn't define those in term.h, where they're used */ +#ifndef OK +#define OK (0) +#endif +#ifndef ERR +#define ERR (-1) +#endif + static char bufout[256]; static struct termios tsave; static struct termios tsacc; static Item *curentry; +static int termset = ERR; void uisetup(void) t@@ -28,7 +37,9 @@ uisetup(void) tsacc.c_cc[VTIME] = 0; tcsetattr(0, TCSANOW, &tsacc); - setupterm(NULL, 1, NULL); + if (termset != OK) + /* setupterm call exits on error */ + termset = setupterm(NULL, 1, NULL); putp(tparm(clear_screen, 0, 0, 0, 0, 0, 0, 0, 0, 0)); putp(tparm(save_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0)); putp(tparm(change_scroll_region, 0, lines-2, 0, 0, 0, 0, 0, 0, 0)); t@@ -39,6 +50,9 @@ uisetup(void) void uicleanup(void) { + if (termset != OK) + return; + putp(tparm(change_scroll_region, 0, lines-1, 0, 0, 0, 0, 0, 0, 0)); putp(tparm(clear_screen, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tcsetattr(0, TCSANOW, &tsave); t@@ -565,7 +579,9 @@ uisigwinch(int signal) { Dir *dir; - setupterm(NULL, 1, NULL); + if (termset == OK) + del_curterm(cur_term); + termset = setupterm(NULL, 1, NULL); putp(tparm(change_scroll_region, 0, lines-2, 0, 0, 0, 0, 0, 0, 0)); if (!curentry || !(dir = curentry->dat))