|
|
fix a memory leak when resizing the window - sfeed_curses - sfeed curses UI (now part of sfeed, development is in sfeed) |
|
|
 |
git clone git://git.codemadness.org/sfeed_curses (git://git.codemadness.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
README |
|
|
 |
LICENSE |
|
|
|
--- |
|
|
 |
commit ddf5df16b38ffae681dea75408146b51c0daeda0 |
|
|
 |
parent d59a1ec6aa2733c24906e37a0cf18170ceb14f5f |
|
|
 |
Author: Hiltjo Posthuma <hiltjo@codemadness.org> (mailto://) |
application/vnd.lotus-organizer |
|
|
Date: Fri, 19 Mar 2021 22:19:19 +0100 |
|
|
|
|
|
|
|
fix a memory leak when resizing the window |
|
|
|
|
|
|
|
This happened because setupterm() was called on each resize. ncurses internally |
|
|
|
then allocates a new structure every time on calling setupterm(). It also |
|
|
|
rereads the terminfo file and entries which is wasteful. |
|
|
|
|
|
|
|
Now it is setup once and only rereads the terminal dimensions using the ioctl |
|
|
|
directly. The global curses variables `columns` and `lines` are not used |
|
|
|
anymore. |
|
|
|
|
|
|
|
Note: the contents of the rows and columns are checked, because the ioctl can |
|
|
|
succeed, but return zero values, for example on serial consoles. |
|
|
|
|
|
|
|
Diffstat: |
|
|
|
M sfeed_curses.c | 10 +++++++--- |
|
|
|
|
|
|
|
1 file changed, 7 insertions(+), 3 deletions(-) |
|
|
|
--- |
|
|
 |
diff --git a/sfeed_curses.c b/sfeed_curses.c |
|
|
|
@@ -1,3 +1,4 @@ |
|
|
|
+#include <sys/ioctl.h> |
|
|
|
#include <sys/select.h> |
|
|
|
#include <sys/time.h> |
|
|
|
#include <sys/types.h> |
|
|
|
@@ -622,9 +623,11 @@ win_update(struct win *w, int width, int height) |
|
|
|
void |
|
|
|
resizewin(void) |
|
|
|
{ |
|
|
|
- setupterm(NULL, 1, NULL); |
|
|
|
- /* termios globals are changed: `lines` and `columns` */ |
|
|
|
- win_update(&win, columns, lines); |
|
|
|
+ struct winsize winsz; |
|
|
|
+ |
|
|
|
+ if (ioctl(1, TIOCGWINSZ, &winsz) != -1 && |
|
|
|
+ winsz.ws_col > 0 && winsz.ws_row > 0) |
|
|
|
+ win_update(&win, winsz.ws_col, winsz.ws_row); |
|
|
|
if (win.dirty) |
|
|
|
alldirty(); |
|
|
|
} |
|
|
|
@@ -641,6 +644,7 @@ init(void) |
|
|
|
tcur.c_cc[VTIME] = 0; |
|
|
|
tcsetattr(0, TCSANOW, &tcur); |
|
|
|
|
|
|
|
+ setupterm(NULL, 1, NULL); |
|
|
|
resizewin(); |
|
|
|
|
|
|
|
appmode(1); |
|