summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole
authorerik <erik>2007-01-19 01:12:38 (UTC)
committer erik <erik>2007-01-19 01:12:38 (UTC)
commit1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7 (patch) (unidiff)
treeaf4a12bc46e25853386dc53868b869e1bf05d863 /core/apps/embeddedkonsole
parent2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a (diff)
downloadopie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.zip
opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.gz
opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.bz2
Every single file in this commit had a memory leak where a resource is
allocated in the constructor but not de-allocated in the destructor. This commit fixes that.
Diffstat (limited to 'core/apps/embeddedkonsole') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEScreen.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp
index 1db34d2..30ff49d 100644
--- a/core/apps/embeddedkonsole/TEScreen.cpp
+++ b/core/apps/embeddedkonsole/TEScreen.cpp
@@ -56,47 +56,47 @@
56 56
57#define HERE printf("%s(%d): here\n",__FILE__,__LINE__) 57#define HERE printf("%s(%d): here\n",__FILE__,__LINE__)
58 58
59//FIXME: this is emulation specific. Use FALSE for xterm, TRUE for ANSI. 59//FIXME: this is emulation specific. Use FALSE for xterm, TRUE for ANSI.
60//FIXME: see if we can get this from terminfo. 60//FIXME: see if we can get this from terminfo.
61#define BS_CLEARS FALSE 61#define BS_CLEARS FALSE
62 62
63#define loc(X,Y) ((Y) * columns + (X)) 63#define loc(X,Y) ((Y) * columns + (X))
64 64
65/*! creates a `TEScreen' of `lines' lines and `columns' columns. 65/*! creates a `TEScreen' of `lines' lines and `columns' columns.
66*/ 66*/
67 67
68TEScreen::TEScreen(int lines, int columns) 68TEScreen::TEScreen(int _lines, int _columns) :
69 lines(_lines),
70 columns(_columns),
71 tabstops(0),
72 histCursor(0),
73 horzCursor(0)
69{ 74{
70 this->lines = lines;
71 this->columns = columns;
72// odebug << "Columns " << columns << "" << oendl; 75// odebug << "Columns " << columns << "" << oendl;
73 76
74 image = (ca*) malloc(lines*columns*sizeof(ca)); 77 image = new ca[lines*columns];
75 tabstops = NULL; initTabStops(); 78 initTabStops();
76
77 histCursor = 0;
78 horzCursor = 0;
79 79
80 clearSelection(); 80 clearSelection();
81 reset(); 81 reset();
82} 82}
83 83
84/*! Destructor 84/*! Destructor
85*/ 85*/
86 86
87TEScreen::~TEScreen() 87TEScreen::~TEScreen()
88{ 88{
89 free(image); 89 delete [] image;
90 if (tabstops) free(tabstops); 90 delete [] tabstops;
91} 91}
92 92
93/* ------------------------------------------------------------------------- */ 93/* ------------------------------------------------------------------------- */
94/* */ 94/* */
95/* Normalized Screen Operations */ 95/* Normalized Screen Operations */
96/* */ 96/* */
97/* ------------------------------------------------------------------------- */ 97/* ------------------------------------------------------------------------- */
98 98
99// Cursor Setting -------------------------------------------------------------- 99// Cursor Setting --------------------------------------------------------------
100 100
101/*! \section Cursor 101/*! \section Cursor
102 102
@@ -387,47 +387,47 @@ void TEScreen::restoreCursor()
387 387
388void TEScreen::resizeImage(int new_lines, int new_columns) 388void TEScreen::resizeImage(int new_lines, int new_columns)
389{ 389{
390 if (cuY > new_lines-1) { 390 if (cuY > new_lines-1) {
391// attempt to preserve focus and lines 391// attempt to preserve focus and lines
392 bmargin = lines-1; //FIXME: margin lost 392 bmargin = lines-1; //FIXME: margin lost
393 for (int i = 0; i < cuY-(new_lines-1); i++) { 393 for (int i = 0; i < cuY-(new_lines-1); i++) {
394 addHistLine(); scrollUp(horzCursor,1); 394 addHistLine(); scrollUp(horzCursor,1);
395 } 395 }
396 } 396 }
397 397
398 // make new image 398 // make new image
399 ca* newimg = (ca*)malloc( new_lines * new_columns * sizeof( ca)); 399 ca* newimg = new ca[new_lines * new_columns];
400 400
401 clearSelection(); 401 clearSelection();
402 402
403 // clear new image 403 // clear new image
404 for (int y = 0; y < new_lines; y++) 404 for (int y = 0; y < new_lines; y++)
405 for (int x = 0; x < new_columns; x++) { 405 for (int x = 0; x < new_columns; x++) {
406 newimg[y*new_columns+x].c = ' '; 406 newimg[y*new_columns+x].c = ' ';
407 newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR; 407 newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR;
408 newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR; 408 newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR;
409 newimg[y*new_columns+x].r = DEFAULT_RENDITION; 409 newimg[y*new_columns+x].r = DEFAULT_RENDITION;
410 } 410 }
411 int cpy_lines = QMIN(new_lines, lines); 411 int cpy_lines = QMIN(new_lines, lines);
412 int cpy_columns = QMIN(new_columns,columns); 412 int cpy_columns = QMIN(new_columns,columns);
413 // copy to new image 413 // copy to new image
414 for (int y = 0; y < cpy_lines; y++) 414 for (int y = 0; y < cpy_lines; y++)
415 for (int x = 0; x < cpy_columns; x++) { 415 for (int x = 0; x < cpy_columns; x++) {
416 newimg[y*new_columns+x].c = image[loc(x,y)].c; 416 newimg[y*new_columns+x].c = image[loc(x,y)].c;
417 newimg[y*new_columns+x].f = image[loc(x,y)].f; 417 newimg[y*new_columns+x].f = image[loc(x,y)].f;
418 newimg[y*new_columns+x].b = image[loc(x,y)].b; 418 newimg[y*new_columns+x].b = image[loc(x,y)].b;
419 newimg[y*new_columns+x].r = image[loc(x,y)].r; 419 newimg[y*new_columns+x].r = image[loc(x,y)].r;
420 } 420 }
421 free(image); 421 delete [] image;
422 image = newimg; 422 image = newimg;
423 lines = new_lines; 423 lines = new_lines;
424 columns = new_columns; 424 columns = new_columns;
425 cuX = QMIN(cuX,columns-1); 425 cuX = QMIN(cuX,columns-1);
426 cuY = QMIN(cuY,lines-1); 426 cuY = QMIN(cuY,lines-1);
427 427
428 // FIXME: try to keep values, evtl. 428 // FIXME: try to keep values, evtl.
429 tmargin=0; 429 tmargin=0;
430 bmargin=lines-1; 430 bmargin=lines-1;
431 initTabStops(); 431 initTabStops();
432 clearSelection(); 432 clearSelection();
433} 433}
@@ -498,25 +498,25 @@ void TEScreen::effectiveRendition()
498 returns the image. 498 returns the image.
499 499
500 Get the size of the image by \sa getLines and \sa getColumns. 500 Get the size of the image by \sa getLines and \sa getColumns.
501 501
502 NOTE that the image returned by this function must later be 502 NOTE that the image returned by this function must later be
503 freed. 503 freed.
504 504
505*/ 505*/
506 506
507ca* TEScreen::getCookedImage() 507ca* TEScreen::getCookedImage()
508{ 508{
509 int x,y; 509 int x,y;
510 ca* merged = (ca*)malloc(lines*columns*sizeof(ca)); 510 ca* merged = new ca[lines*columns];
511 ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); 511 ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION);
512 512
513 if (histCursor > hist.getLines()) { 513 if (histCursor > hist.getLines()) {
514 histCursor = hist.getLines(); 514 histCursor = hist.getLines();
515 } 515 }
516 516
517 for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) 517 for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++)
518 { 518 {
519 int len = QMIN(columns,hist.getLineLen(y+histCursor)); 519 int len = QMIN(columns,hist.getLineLen(y+histCursor));
520 int yp = y*columns; 520 int yp = y*columns;
521 int yq = (y+histCursor)*columns; 521 int yq = (y+histCursor)*columns;
522 522
@@ -614,26 +614,28 @@ void TEScreen::clearTabStops()
614{ 614{
615 for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE; 615 for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE;
616} 616}
617 617
618void TEScreen::changeTabStop(bool set) 618void TEScreen::changeTabStop(bool set)
619{ 619{
620 if (cuX >= columns) return; 620 if (cuX >= columns) return;
621 tabstops[cuX] = set; 621 tabstops[cuX] = set;
622} 622}
623 623
624void TEScreen::initTabStops() 624void TEScreen::initTabStops()
625{ 625{
626 if (tabstops) free(tabstops); 626 if (tabstops)
627 tabstops = (bool*)malloc(columns*sizeof(bool)); 627 delete [] tabstops;
628
629 tabstops = new bool[columns];
628 // Arrg! The 1st tabstop has to be one longer than the other. 630 // Arrg! The 1st tabstop has to be one longer than the other.
629 // i.e. the kids start counting from 0 instead of 1. 631 // i.e. the kids start counting from 0 instead of 1.
630 // Other programs might behave correctly. Be aware. 632 // Other programs might behave correctly. Be aware.
631 for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); 633 for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0);
632} 634}
633 635
634/*! 636/*!
635 This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) 637 This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine)
636 depending on the NewLine Mode (LNM). This mode also 638 depending on the NewLine Mode (LNM). This mode also
637 affects the key sequence returned for newline ([CR]LF). 639 affects the key sequence returned for newline ([CR]LF).
638*/ 640*/
639 641