diff options
author | 2009-06-04 14:48:07 +0000 | |
---|---|---|
committer | 2009-06-04 14:48:07 +0000 | |
commit | c26886960beab64d89a8319e611e9f663a54cf9a (patch) | |
tree | fb57e475dd4a689217dfcf654f503389126338a0 | |
parent | Okay, so I screwed up when testing this, doh. Unbreak so that CAN/SUB actually (diff) | |
download | wireguard-openbsd-c26886960beab64d89a8319e611e9f663a54cf9a.tar.xz wireguard-openbsd-c26886960beab64d89a8319e611e9f663a54cf9a.zip |
Plug memory leak when the terminal is resized.
Reported by Simon Bertrang, thanks.
-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; } |