diff --git a/src/syncterm/bbslist.c b/src/syncterm/bbslist.c index ae3c2b4955067417b1539d3f83efcb86e2c8ef80..9f87795f21043bdc5a501993e5025b5c99d1fd53 100644 --- a/src/syncterm/bbslist.c +++ b/src/syncterm/bbslist.c @@ -46,7 +46,7 @@ void viewofflinescroll(void) x=wherex(); y=wherey(); gettextinfo(&txtinfo); - scrnbuf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + scrnbuf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrnbuf); uifcbail(); drawwin(); @@ -124,7 +124,6 @@ void viewofflinescroll(void) } init_uifc(TRUE, TRUE); puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrnbuf); - free(scrnbuf); gotoxy(x,y); return; } diff --git a/src/syncterm/fonts.c b/src/syncterm/fonts.c index 14acc9711a71239fef34e576aab8877f56dfb65d..11241774ad2a27f1566c039fef3da95ff12d1029 100644 --- a/src/syncterm/fonts.c +++ b/src/syncterm/fonts.c @@ -325,7 +325,7 @@ void font_management(void) struct text_info ti; gettextinfo(&ti); - savbuf=(char *)malloc((ti.screenheight-2)*ti.screenwidth*2); + savbuf=(char *)alloca((ti.screenheight-2)*ti.screenwidth*2); if(savbuf==NULL) { uifc.msg("malloc() failure."); continue; @@ -338,7 +338,6 @@ void font_management(void) } filepick_free(&fpick); puttext(1,2,ti.screenwidth,ti.screenheight-1,savbuf); - free(savbuf); } } } diff --git a/src/syncterm/menu.c b/src/syncterm/menu.c index 0076b71d45a6176b2732354b0d9070b40db7bda7..e32002f7cf57b39041656dee806399ec8ef280d5 100644 --- a/src/syncterm/menu.c +++ b/src/syncterm/menu.c @@ -27,7 +27,8 @@ void viewscroll(void) y=wherey(); uifcbail(); gettextinfo(&txtinfo); - scrollback=(char *)malloc((scrollback_buf==NULL?0:(term.width*2*settings.backlines))+(txtinfo.screenheight*txtinfo.screenwidth*2)); + /* ToDo: Watch this... may be too large for alloca() */ + scrollback=(char *)alloca((scrollback_buf==NULL?0:(term.width*2*settings.backlines))+(txtinfo.screenheight*txtinfo.screenwidth*2)); if(cterm.scrollback != NULL) memcpy(scrollback,cterm.scrollback,term.width*2*settings.backlines); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrollback+(cterm.backpos)*cterm.width*2); @@ -105,7 +106,6 @@ void viewscroll(void) } } puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrollback+(cterm.backpos)*cterm.width*2); - free(scrollback); gotoxy(x,y); return; } @@ -132,7 +132,7 @@ int syncmenu(struct bbslist *bbs, int *speed) int ret; gettextinfo(&txtinfo); - buf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); if(cio_api.mode!=CIOLIB_MODE_CURSES @@ -235,13 +235,11 @@ int syncmenu(struct bbslist *bbs, int *speed) ret=i; uifcbail(); puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); - free(buf); return(ret); } } uifcbail(); puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); - free(buf); return(ret); } diff --git a/src/syncterm/term.c b/src/syncterm/term.c index ab8ebe18f037a6a940995e77898626839c686189..dfc739753b73d4fc24518c5c3b56d0919ee25358 100644 --- a/src/syncterm/term.c +++ b/src/syncterm/term.c @@ -53,8 +53,8 @@ void mousedrag(unsigned char *scrollback) int lastchar; sbufsize=term.width*2*term.height; - screen=(unsigned char*)malloc(sbufsize); - sbuffer=(unsigned char*)malloc(sbufsize); + screen=(unsigned char*)alloca(sbufsize); + sbuffer=(unsigned char*)alloca(sbufsize); gettext(term.x-1,term.y-1,term.x+term.width-2,term.y+term.height-2,screen); while(1) { key=getch(); @@ -90,7 +90,7 @@ void mousedrag(unsigned char *scrollback) break; default: lines=abs(mevent.endy-mevent.starty)+1; - copybuf=malloc(endpos-startpos+4+lines*2); + copybuf=alloca(endpos-startpos+4+lines*2); outpos=0; lastchar=0; for(pos=startpos;pos<=endpos;pos++) { @@ -107,17 +107,12 @@ void mousedrag(unsigned char *scrollback) copybuf[outpos]=0; copytext(copybuf, strlen(copybuf)); puttext(term.x-1,term.y-1,term.x+term.width-2,term.y+term.height-2,screen); - free(copybuf); - free(screen); - free(sbuffer); return; } break; default: puttext(term.x-1,term.y-1,term.x+term.width-2,term.y+term.height-2,screen); ungetch(key); - free(screen); - free(sbuffer); return; } } @@ -935,7 +930,7 @@ void music_control(struct bbslist *bbs) }; gettextinfo(&txtinfo); - buf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); init_uifc(FALSE, FALSE); @@ -967,7 +962,6 @@ void music_control(struct bbslist *bbs) window(txtinfo.winleft,txtinfo.wintop,txtinfo.winright,txtinfo.winbottom); textattr(txtinfo.attribute); gotoxy(txtinfo.curx,txtinfo.cury); - free(buf); } void font_control(struct bbslist *bbs) @@ -979,7 +973,7 @@ void font_control(struct bbslist *bbs) if(safe_mode) return; gettextinfo(&txtinfo); - buf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); init_uifc(FALSE, FALSE); @@ -1004,7 +998,6 @@ void font_control(struct bbslist *bbs) window(txtinfo.winleft,txtinfo.wintop,txtinfo.winright,txtinfo.winbottom); textattr(txtinfo.attribute); gotoxy(txtinfo.curx,txtinfo.cury); - free(buf); } void capture_control(struct bbslist *bbs) @@ -1016,7 +1009,7 @@ void capture_control(struct bbslist *bbs) if(safe_mode) return; gettextinfo(&txtinfo); - buf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); init_uifc(FALSE, FALSE); @@ -1089,7 +1082,6 @@ void capture_control(struct bbslist *bbs) window(txtinfo.winleft,txtinfo.wintop,txtinfo.winright,txtinfo.winbottom); textattr(txtinfo.attribute); gotoxy(txtinfo.curx,txtinfo.cury); - free(buf); } BOOL doterm(struct bbslist *bbs) @@ -1391,13 +1383,12 @@ BOOL doterm(struct bbslist *bbs) struct text_info txtinfo; gettextinfo(&txtinfo); - buf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); i=0; init_uifc(FALSE, FALSE); if(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Disconnect... Are you sure?",opts)==0) { uifcbail(); - free(buf); cterm_write("\x0c",1,NULL,0,NULL); /* Clear screen into scrollback */ scrollback_lines=cterm.backpos; cterm_end(); @@ -1410,7 +1401,6 @@ BOOL doterm(struct bbslist *bbs) window(txtinfo.winleft,txtinfo.wintop,txtinfo.winright,txtinfo.winbottom); textattr(txtinfo.attribute); gotoxy(txtinfo.curx,txtinfo.cury); - free(buf); showmouse(); } break; diff --git a/src/syncterm/uifcinit.c b/src/syncterm/uifcinit.c index 5dfdb442daa0985d8d2fb9793029a0e3936513a6..205acc0120752d294bbb5c822e77da9d3b99866f 100644 --- a/src/syncterm/uifcinit.c +++ b/src/syncterm/uifcinit.c @@ -79,7 +79,7 @@ void uifcmsg(char *msg, char *helpbuf) gettextinfo(&txtinfo); i=uifc_initialized; if(!i) { - buf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); } init_uifc(FALSE, FALSE); @@ -92,7 +92,6 @@ void uifcmsg(char *msg, char *helpbuf) if(!i) { uifcbail(); puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); - free(buf); } } @@ -111,7 +110,7 @@ int confirm(char *msg, char *helpbuf) gettextinfo(&txtinfo); i=uifc_initialized; if(!i) { - buf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2); + buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2); gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); } init_uifc(FALSE, FALSE); @@ -123,7 +122,6 @@ int confirm(char *msg, char *helpbuf) if(!i) { uifcbail(); puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf); - free(buf); } return(ret); } diff --git a/src/syncterm/window.c b/src/syncterm/window.c index c8835dfe2d0b022c8c56319d8c58300cf0a8531f..81ce3d69f98459c4f76445293f90c0d39dfd480e 100644 --- a/src/syncterm/window.c +++ b/src/syncterm/window.c @@ -23,7 +23,7 @@ int drawwin(void) } term.x=(txtinfo.screenwidth-term.width)/2+2; term.y=(txtinfo.screenheight-term.height)/2+2; - if((winbuf=(char *)malloc(txtinfo.screenheight*txtinfo.screenwidth*2))==NULL) { + if((winbuf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2))==NULL) { uifcmsg("Cannot allocate memory for terminal buffer", "`Memory error`\n\n" "Either your system is dangerously low on resources or your\n" "window is farking huge!"); @@ -46,6 +46,5 @@ int drawwin(void) } } puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,winbuf); - free(winbuf); return(0); }