diff options
author | Can Erkin Acar <canacar@cvs.openbsd.org> | 2009-06-04 14:48:08 +0000 |
---|---|---|
committer | Can Erkin Acar <canacar@cvs.openbsd.org> | 2009-06-04 14:48:08 +0000 |
commit | 057aeb005eeedfb693f2ad9bf4c17fe41c3bc4f6 (patch) | |
tree | 1088e9de203fd4e39640ad0156b9cf426a58c471 /usr.bin | |
parent | f5807c0bbf7c08a31f367d1f66aec267447a1aef (diff) |
Plug memory leak when the terminal is resized.
Reported by Simon Bertrang, thanks.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/systat/engine.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/usr.bin/systat/engine.c b/usr.bin/systat/engine.c index 57a82876fbe..27c0b59a028 100644 --- a/usr.bin/systat/engine.c +++ b/usr.bin/systat/engine.c @@ -1,4 +1,4 @@ -/* $Id: engine.c,v 1.7 2008/12/07 02:56:06 canacar Exp $ */ +/* $Id: engine.c,v 1.8 2009/06/04 14:48:07 canacar Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org> * @@ -25,8 +25,18 @@ #include <signal.h> #include <stdlib.h> #include <string.h> +#include <term.h> #include <unistd.h> +/* XXX These are defined in term.h and conflict with our variable names */ +#ifdef columns +#undef columns +#endif + +#ifdef lines +#undef lines +#endif + #include "engine.h" #ifndef MIN @@ -1033,6 +1043,32 @@ setup_term(int dmax) field_setup(); } +void +resize_term(void) +{ + struct winsize ws; + + if (rawmode) + return; + + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1) + return; + + resizeterm(ws.ws_row, ws.ws_col); + + columns = COLS; + lines = LINES; + + maxprint = max_disp; + + if (maxprint == 0 || maxprint > lines - HEADER_LINES) + maxprint = lines - HEADER_LINES; + + clear(); + + field_setup(); +} + struct command * command_set(struct command *cmd, const char *init) { @@ -1279,9 +1315,7 @@ engine_loop(int countmax) if (gotsig_close) break; if (gotsig_resize) { - if (rawmode == 0) - endwin(); - setup_term(max_disp); + resize_term(); gotsig_resize = 0; need_update = 1; } |