diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2009-05-26 02:21:02 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2009-05-26 02:21:02 +0200 |
| commit | 129bcd7586968ed882e41c0df76c5c0c0c414e6d (patch) | |
| tree | e8d47b2b3bba47340b2d78ea48f9c89a078e8f18 | |
| parent | 059d2ba264f8ee2f6fbdb4d7199b611433ad8a72 (diff) | |
| download | st-129bcd7586968ed882e41c0df76c5c0c0c414e6d.tar.gz st-129bcd7586968ed882e41c0df76c5c0c0c414e6d.zip | |
fixed a memory leak & segfault in tresize.
| -rw-r--r-- | st.c | 25 |
1 files changed, 16 insertions, 9 deletions
| @@ -573,7 +573,7 @@ void | |||
| 573 | tputc(char c) { | 573 | tputc(char c) { |
| 574 | static int inesc = 0; | 574 | static int inesc = 0; |
| 575 | 575 | ||
| 576 | dump(c); | 576 | //dump(c); |
| 577 | /* start of escseq */ | 577 | /* start of escseq */ |
| 578 | if(c == '\033') | 578 | if(c == '\033') |
| 579 | escreset(), inesc = 1; | 579 | escreset(), inesc = 1; |
| @@ -636,20 +636,24 @@ tresize(int col, int row) { | |||
| 636 | 636 | ||
| 637 | if(col < 1 || row < 1) | 637 | if(col < 1 || row < 1) |
| 638 | return; | 638 | return; |
| 639 | /* alloc */ | ||
| 639 | line = calloc(row, sizeof(Line)); | 640 | line = calloc(row, sizeof(Line)); |
| 640 | for(i = 0 ; i < row; i++) | 641 | for(i = 0 ; i < row; i++) |
| 641 | line[i] = calloc(col, sizeof(Glyph)); | 642 | line[i] = calloc(col, sizeof(Glyph)); |
| 642 | for(i = 0 ; i < minrow; i++) { | 643 | /* copy */ |
| 643 | memcpy(line[i], term.line[i], mincol * sizeof(Glyph)); | 644 | for(i = 0 ; i < minrow; i++) |
| 644 | free(term.line[i]); | 645 | memcpy(line[i], term.line[i], mincol * sizeof(Glyph)); |
| 645 | } | 646 | /* free */ |
| 647 | for(i = 0; i < term.row; i++) | ||
| 648 | free(term.line[i]); | ||
| 646 | free(term.line); | 649 | free(term.line); |
| 650 | |||
| 647 | LIMIT(term.c.x, 0, col-1); | 651 | LIMIT(term.c.x, 0, col-1); |
| 648 | LIMIT(term.c.y, 0, row-1); | 652 | LIMIT(term.c.y, 0, row-1); |
| 649 | LIMIT(term.top, 0, row-1); | 653 | LIMIT(term.top, 0, row-1); |
| 650 | LIMIT(term.bot, 0, row-1); | 654 | LIMIT(term.bot, 0, row-1); |
| 651 | // if(term.bot == term.row-1) | 655 | |
| 652 | term.bot = row-1; | 656 | term.bot = row-1; |
| 653 | term.line = line; | 657 | term.line = line; |
| 654 | term.col = col, term.row = row; | 658 | term.col = col, term.row = row; |
| 655 | } | 659 | } |
| @@ -775,7 +779,10 @@ xcursor(int mode) { | |||
| 775 | static int oldx = 0; | 779 | static int oldx = 0; |
| 776 | static int oldy = 0; | 780 | static int oldy = 0; |
| 777 | Glyph g = {' ', ATnone, DefaultBG, DefaultCS, 0}; | 781 | Glyph g = {' ', ATnone, DefaultBG, DefaultCS, 0}; |
| 778 | 782 | ||
| 783 | LIMIT(oldx, 0, term.col-1); | ||
| 784 | LIMIT(oldy, 0, term.row-1); | ||
| 785 | |||
| 779 | if(term.line[term.c.y][term.c.x].state & CRset) | 786 | if(term.line[term.c.y][term.c.x].state & CRset) |
| 780 | g.c = term.line[term.c.y][term.c.x].c; | 787 | g.c = term.line[term.c.y][term.c.x].c; |
| 781 | /* remove the old cursor */ | 788 | /* remove the old cursor */ |
| @@ -859,7 +866,7 @@ resize(XEvent *e) { | |||
| 859 | col = e->xconfigure.width / xw.cw; | 866 | col = e->xconfigure.width / xw.cw; |
| 860 | row = e->xconfigure.height / xw.ch; | 867 | row = e->xconfigure.height / xw.ch; |
| 861 | 868 | ||
| 862 | if(term.col != col && term.row != row) { | 869 | if(term.col != col || term.row != row) { |
| 863 | tresize(col, row); | 870 | tresize(col, row); |
| 864 | ttyresize(col, row); | 871 | ttyresize(col, row); |
| 865 | xw.w = e->xconfigure.width; | 872 | xw.w = e->xconfigure.width; |
