[hackers] [st] fixed a memory leak & segfault in tresize. || Aur?lien Aptel

From: <hg_AT_suckless.org>
Date: Mon, 25 May 2009 22:22:12 +0000 (UTC)

changeset: 53:6516c46134f0
tag: tip
user: Aur?lien Aptel <aurelien.aptel_AT_gmail.com>
date: Tue May 26 02:21:02 2009 +0200
files: st.c
description:
fixed a memory leak & segfault in tresize.

diff -r aeb4d8936f8a -r 6516c46134f0 st.c
--- a/st.c Fri May 15 00:40:47 2009 +0200
+++ b/st.c Tue May 26 02:21:02 2009 +0200
@@ -573,7 +573,7 @@
 tputc(char c) {
         static int inesc = 0;
 
- dump(c);
+ //dump(c);
         /* start of escseq */
         if(c == '\033')
                 escreset(), inesc = 1;
@@ -636,20 +636,24 @@
 
         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 @@
         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 @@
         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;
Received on Mon May 25 2009 - 22:22:12 UTC

This archive was generated by hypermail 2.2.0 : Mon May 25 2009 - 22:24:05 UTC