summaryrefslogtreecommitdiff
path: root/core
authorerik <erik>2007-01-19 01:12:38 (UTC)
committer erik <erik>2007-01-19 01:12:38 (UTC)
commit1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7 (patch) (side-by-side diff)
treeaf4a12bc46e25853386dc53868b869e1bf05d863 /core
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') (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
@@ -62,35 +62,35 @@
#define loc(X,Y) ((Y) * columns + (X))
/*! creates a `TEScreen' of `lines' lines and `columns' columns.
*/
-TEScreen::TEScreen(int lines, int columns)
+TEScreen::TEScreen(int _lines, int _columns) :
+ lines(_lines),
+ columns(_columns),
+ tabstops(0),
+ histCursor(0),
+ horzCursor(0)
{
- this->lines = lines;
- this->columns = columns;
// odebug << "Columns " << columns << "" << oendl;
- image = (ca*) malloc(lines*columns*sizeof(ca));
- tabstops = NULL; initTabStops();
-
- histCursor = 0;
- horzCursor = 0;
+ image = new ca[lines*columns];
+ initTabStops();
clearSelection();
reset();
}
/*! Destructor
*/
TEScreen::~TEScreen()
{
- free(image);
- if (tabstops) free(tabstops);
+ delete [] image;
+ delete [] tabstops;
}
/* ------------------------------------------------------------------------- */
/* */
/* Normalized Screen Operations */
/* */
@@ -393,13 +393,13 @@ void TEScreen::resizeImage(int new_lines, int new_columns)
for (int i = 0; i < cuY-(new_lines-1); i++) {
addHistLine(); scrollUp(horzCursor,1);
}
}
// make new image
- ca* newimg = (ca*)malloc( new_lines * new_columns * sizeof( ca));
+ ca* newimg = new ca[new_lines * new_columns];
clearSelection();
// clear new image
for (int y = 0; y < new_lines; y++)
for (int x = 0; x < new_columns; x++) {
@@ -415,13 +415,13 @@ void TEScreen::resizeImage(int new_lines, int new_columns)
for (int x = 0; x < cpy_columns; x++) {
newimg[y*new_columns+x].c = image[loc(x,y)].c;
newimg[y*new_columns+x].f = image[loc(x,y)].f;
newimg[y*new_columns+x].b = image[loc(x,y)].b;
newimg[y*new_columns+x].r = image[loc(x,y)].r;
}
- free(image);
+ delete [] image;
image = newimg;
lines = new_lines;
columns = new_columns;
cuX = QMIN(cuX,columns-1);
cuY = QMIN(cuY,lines-1);
@@ -504,13 +504,13 @@ void TEScreen::effectiveRendition()
*/
ca* TEScreen::getCookedImage()
{
int x,y;
- ca* merged = (ca*)malloc(lines*columns*sizeof(ca));
+ ca* merged = new ca[lines*columns];
ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION);
if (histCursor > hist.getLines()) {
histCursor = hist.getLines();
}
@@ -620,14 +620,16 @@ void TEScreen::changeTabStop(bool set)
if (cuX >= columns) return;
tabstops[cuX] = set;
}
void TEScreen::initTabStops()
{
- if (tabstops) free(tabstops);
- tabstops = (bool*)malloc(columns*sizeof(bool));
+ if (tabstops)
+ delete [] tabstops;
+
+ tabstops = new bool[columns];
// Arrg! The 1st tabstop has to be one longer than the other.
// i.e. the kids start counting from 0 instead of 1.
// Other programs might behave correctly. Be aware.
for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0);
}