From: brynet Date: Fri, 10 Apr 2015 18:05:51 +0000 (+0000) Subject: This changes vi to use resizeterm(3) instead of reinitializing curses on X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f43ccfb1789ce9c692e98716be800037eadc1655;p=openbsd This changes vi to use resizeterm(3) instead of reinitializing curses on window resizes, which was leaking massive amounts of memory. Try observing vi in top(1) and while resizing the window a few times before and aftering applying this diff.. Also some more comment cleanup and another memory leak.. From github.com/lichray/nvi2 879d2ad6dd4a4343eb0a588ebfe637e1c9845bc4 a8c38480adb030a05bbb2aafec6067dd65d8c2eb ok millert@ --- diff --git a/usr.bin/vi/cl/cl_screen.c b/usr.bin/vi/cl/cl_screen.c index f5ee598fe59..6fafff1f849 100644 --- a/usr.bin/vi/cl/cl_screen.c +++ b/usr.bin/vi/cl/cl_screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_screen.c,v 1.22 2014/11/12 16:29:04 millert Exp $ */ +/* $OpenBSD: cl_screen.c,v 1.23 2015/04/10 18:05:51 brynet Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -52,7 +52,9 @@ cl_screen(SCR *sp, u_int32_t flags) /* See if the current information is incorrect. */ if (F_ISSET(gp, G_SRESTART)) { - if (cl_quit(gp)) + if ((!F_ISSET(sp, SC_SCR_EX | SC_SCR_VI) || + resizeterm(O_VAL(sp, O_LINES), O_VAL(sp, O_COLUMNS))) && + cl_quit(gp)) return (1); F_CLR(gp, G_SRESTART); } @@ -221,19 +223,15 @@ cl_vi_init(SCR *sp) o_cols = getenv("COLUMNS"); cl_putenv("COLUMNS", NULL, (u_long)O_VAL(sp, O_COLUMNS)); + /* + * The terminal is aways initialized, either in `main`, or by a + * previous call to newterm(3). + */ + (void)del_curterm(cur_term); + /* * We don't care about the SCREEN reference returned by newterm, we * never have more than one SCREEN at a time. - * - * XXX - * The SunOS initscr() can't be called twice. Don't even think about - * using it. It fails in subtle ways (e.g. select(2) on fileno(stdin) - * stops working). (The SVID notes that applications should only call - * initscr() once.) - * - * XXX - * The HP/UX newterm doesn't support the NULL first argument, so we - * have to specify the terminal type. */ errno = 0; if (newterm(ttype, stdout, stdin) == NULL) { @@ -395,6 +393,9 @@ cl_vi_end(GS *gp) /* End curses window. */ (void)endwin(); + /* Free the SCREEN created by newterm(3). */ + delscreen(set_term(NULL)); + /* * XXX * The screen TE sequence just got sent. See the comment in diff --git a/usr.bin/vi/cl/cl_term.c b/usr.bin/vi/cl/cl_term.c index 8c194373d75..ea5a8bd7d82 100644 --- a/usr.bin/vi/cl/cl_term.c +++ b/usr.bin/vi/cl/cl_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_term.c,v 1.19 2014/11/12 16:29:04 millert Exp $ */ +/* $OpenBSD: cl_term.c,v 1.20 2015/04/10 18:05:51 brynet Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -227,15 +227,16 @@ cl_optchange(SCR *sp, int opt, char *str, u_long *valp) clp = CLP(sp); switch (opt) { + case O_TERM: + F_CLR(sp, SC_SCR_EX | SC_SCR_VI); + /* FALLTHROUGH */ case O_COLUMNS: case O_LINES: - case O_TERM: /* - * Changing the columns, lines or terminal require that - * we restart the screen. + * Changing the terminal type requires that we reinitialize + * curses, while resizing does not. */ F_SET(sp->gp, G_SRESTART); - F_CLR(sp, SC_SCR_EX | SC_SCR_VI); break; case O_MESG: (void)cl_omesg(sp, clp, !*valp);