summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Aptel2009-05-26 02:21:02 +0200
committerAurélien Aptel2009-05-26 02:21:02 +0200
commit129bcd7586968ed882e41c0df76c5c0c0c414e6d (patch)
treee8d47b2b3bba47340b2d78ea48f9c89a078e8f18
parent059d2ba264f8ee2f6fbdb4d7199b611433ad8a72 (diff)
downloadst-129bcd7586968ed882e41c0df76c5c0c0c414e6d.tar.gz
st-129bcd7586968ed882e41c0df76c5c0c0c414e6d.tar.xz
st-129bcd7586968ed882e41c0df76c5c0c0c414e6d.zip
fixed a memory leak & segfault in tresize.
-rw-r--r--st.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/st.c b/st.c
index c24bb1d..8ddfa8b 100644
--- a/st.c
+++ b/st.c
@@ -573,7 +573,7 @@ void
tputc(char c) {
static int inesc = 0;
- dump(c);
+ //dump(c);
/* start of escseq */
if(c == '\033')
escreset(), inesc = 1;
@@ -636,20 +636,24 @@ tresize(int col, int row) {
if(col < 1 || row < 1)
return;
+ /* alloc */
line = calloc(row, sizeof(Line));
for(i = 0 ; i < row; i++)
line[i] = calloc(col, sizeof(Glyph));
- for(i = 0 ; i < minrow; i++) {
- memcpy(line[i], term.line[i], mincol * sizeof(Glyph));
- free(term.line[i]);
- }
+ /* copy */
+ for(i = 0 ; i < minrow; i++)
+ memcpy(line[i], term.line[i], mincol * sizeof(Glyph));
+ /* free */
+ for(i = 0; i < term.row; i++)
+ free(term.line[i]);
free(term.line);
+
LIMIT(term.c.x, 0, col-1);
LIMIT(term.c.y, 0, row-1);
LIMIT(term.top, 0, row-1);
LIMIT(term.bot, 0, row-1);
- // if(term.bot == term.row-1)
- term.bot = row-1;
+
+ term.bot = row-1;
term.line = line;
term.col = col, term.row = row;
}
@@ -775,7 +779,10 @@ xcursor(int mode) {
static int oldx = 0;
static int oldy = 0;
Glyph g = {' ', ATnone, DefaultBG, DefaultCS, 0};
-
+
+ LIMIT(oldx, 0, term.col-1);
+ LIMIT(oldy, 0, term.row-1);
+
if(term.line[term.c.y][term.c.x].state & CRset)
g.c = term.line[term.c.y][term.c.x].c;
/* remove the old cursor */
@@ -859,7 +866,7 @@ resize(XEvent *e) {
col = e->xconfigure.width / xw.cw;
row = e->xconfigure.height / xw.ch;
- if(term.col != col && term.row != row) {
+ if(term.col != col || term.row != row) {
tresize(col, row);
ttyresize(col, row);
xw.w = e->xconfigure.width;