author | erik <erik> | 2007-01-19 01:12:38 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-19 01:12:38 (UTC) |
commit | 1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7 (patch) (unidiff) | |
tree | af4a12bc46e25853386dc53868b869e1bf05d863 /core | |
parent | 2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a (diff) | |
download | opie-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.
-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.cpp | 32 |
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 | |||
@@ -65,17 +65,17 @@ | |||
65 | /*! creates a `TEScreen' of `lines' lines and `columns' columns. | 65 | /*! creates a `TEScreen' of `lines' lines and `columns' columns. |
66 | */ | 66 | */ |
67 | 67 | ||
68 | TEScreen::TEScreen(int lines, int columns) | 68 | TEScreen::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(); |
@@ -86,8 +86,8 @@ TEScreen::TEScreen(int lines, int columns) | |||
86 | 86 | ||
87 | TEScreen::~TEScreen() | 87 | TEScreen::~TEScreen() |
88 | { | 88 | { |
89 | free(image); | 89 | delete [] image; |
90 | if (tabstops) free(tabstops); | 90 | delete [] tabstops; |
91 | } | 91 | } |
92 | 92 | ||
93 | /* ------------------------------------------------------------------------- */ | 93 | /* ------------------------------------------------------------------------- */ |
@@ -396,7 +396,7 @@ void TEScreen::resizeImage(int new_lines, int new_columns) | |||
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 | ||
@@ -418,7 +418,7 @@ void TEScreen::resizeImage(int new_lines, int new_columns) | |||
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; |
@@ -507,7 +507,7 @@ void TEScreen::effectiveRendition() | |||
507 | ca* TEScreen::getCookedImage() | 507 | ca* 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()) { |
@@ -623,8 +623,10 @@ void TEScreen::changeTabStop(bool set) | |||
623 | 623 | ||
624 | void TEScreen::initTabStops() | 624 | void 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. |