summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-16 20:00:25 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-16 20:00:25 +0200
commit2e21435f432191afa1b0f609daa8ca9d4cde1e93 (patch)
treef59b3d80815c2017f4992f0d26e41a439d75e30b
parent6a0d150539897ec65ccc161305db48de10ea35ba (diff)
downloadcolobot-2e21435f432191afa1b0f609daa8ca9d4cde1e93.tar.gz
colobot-2e21435f432191afa1b0f609daa8ca9d4cde1e93.tar.bz2
colobot-2e21435f432191afa1b0f609daa8ca9d4cde1e93.zip
Some memory leaks fixed
-rw-r--r--src/app/app.cpp1
-rw-r--r--src/graphics/engine/text.cpp14
-rw-r--r--src/object/robotmain.cpp26
-rw-r--r--src/ui/edit.cpp56
-rw-r--r--src/ui/interface.cpp1
-rw-r--r--src/ui/maindialog.cpp2
6 files changed, 74 insertions, 26 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 1bf9a54..610cdbb 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -224,6 +224,7 @@ bool CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n");
GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n");
GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n");
+ return true;
}
else
{
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 19ef57b..8fc8709 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -785,18 +785,20 @@ Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont
data.surface = nullptr;
- SDL_FreeSurface(textSurface);
- SDL_FreeSurface(textureSurface);
-
if (! tex.Valid())
{
m_error = "Texture create error";
return texture;
}
+ else
+ {
+ texture.id = tex.id;
+ texture.texSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textureSurface->w, textureSurface->h));
+ texture.charSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textSurface->w, textSurface->h));
+ }
- texture.id = tex.id;
- texture.texSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textureSurface->w, textureSurface->h));
- texture.charSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textSurface->w, textSurface->h));
+ SDL_FreeSurface(textSurface);
+ SDL_FreeSurface(textureSurface);
return texture;
}
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 1c61574..b6aedaa 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -642,6 +642,7 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app)
m_selectObject = 0;
m_infoUsed = 0;
+ m_immediatSatCom = false;
m_beginSatCom = false;
m_movieLock = false;
m_satComLock = false;
@@ -815,11 +816,32 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app)
//! Destructor of robot application
CRobotMain::~CRobotMain()
{
+ delete m_displayText;
+ m_displayText = nullptr;
+
+ delete m_interface;
+ m_interface = nullptr;
+
+ delete m_terrain;
+ m_terrain = nullptr;
+
+ delete m_camera;
+ m_camera = nullptr;
+
+ delete m_displayText;
+ m_displayText = nullptr;
+
delete m_movie;
+ m_movie = nullptr;
+
delete m_dialog;
+ m_dialog = nullptr;
+
delete m_short;
+ m_short = nullptr;
+
delete m_map;
- delete m_terrain;
+ m_map = nullptr;
m_iMan = nullptr;
m_app = nullptr;
@@ -2707,7 +2729,7 @@ void CRobotMain::HiliteObject(Math::Point pos)
if (obj == nullptr)
{
- bool inMap;
+ bool inMap = false;
obj = m_map->DetectMap(pos, inMap);
if (obj == nullptr)
{
diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp
index cde3aee..a4d5961 100644
--- a/src/ui/edit.cpp
+++ b/src/ui/edit.cpp
@@ -79,10 +79,13 @@ CEdit::CEdit () : CControl ()
int i;
m_maxChar = 100;
- m_text = new char[sizeof(char)*(m_maxChar+1)];
+ m_text = new char[m_maxChar+1];
+ memset(m_text, 0, m_maxChar+1);
m_len = 0;
m_app = CApplication::GetInstancePointer();
+ memset(m_lineOffset, 0, sizeof(int) * EDITLINEMAX);
+
m_fontType = Gfx::FONT_COURIER;
m_scroll = 0;
m_bEdit = true;
@@ -102,7 +105,7 @@ CEdit::CEdit () : CControl ()
for ( i=0 ; i<EDITUNDOMAX ; i++ )
{
- m_undo[i].text = 0;
+ m_undo[i].text = nullptr;
}
m_bUndoForce = true;
m_undoOper = OPERUNDO_SPEC;
@@ -119,10 +122,17 @@ CEdit::~CEdit()
for ( i=0 ; i<EDITUNDOMAX ; i++ )
{
delete m_undo[i].text;
+ m_undo[i].text = nullptr;
+ }
+
+ if (m_text != nullptr)
+ {
+ delete[] m_text;
+ m_text = nullptr;
}
- delete m_text;
delete m_scroll;
+ m_scroll = nullptr;
}
@@ -1472,9 +1482,16 @@ bool CEdit::ReadText(const char *filename, int addSize)
m_cursor2 = 0;
FreeImage();
- delete m_text;
- m_text = new char[sizeof(char)*(m_maxChar+1)];
- buffer = new char[sizeof(char)*(m_maxChar+1)];
+
+ if (m_text != nullptr)
+ delete m_text;
+
+ m_text = new char[m_maxChar+1];
+ memset(m_text, 0, m_maxChar+1);
+
+ buffer = new char[m_maxChar+1];
+ memset(buffer, 0, m_maxChar+1);
+
fread(buffer, 1, len, file);
if ( m_format.size() > 0 )
@@ -1934,15 +1951,18 @@ bool CEdit::WriteText(const char *filename)
void CEdit::SetMaxChar(int max)
{
- m_maxChar = max;
FreeImage();
- delete m_text;
- m_text = (char*)malloc(sizeof(char)*(m_maxChar+1));
- if ( m_format.size() > 0 )
- {
+ if (m_text != nullptr)
+ delete[] m_text;
+
+ m_maxChar = max;
+
+ m_text = new char[m_maxChar+1];
+ memset(m_text, 0, m_maxChar+1);
+
+ if (m_format.size() > 0)
m_format.clear();
- }
m_len = 0;
m_cursor1 = 0;
@@ -3062,8 +3082,9 @@ void CEdit::Justif()
if ( m_format.size() == 0 )
{
// TODO check if good
+
i += m_engine->GetText()->Justify(m_text+i, m_fontType,
- m_fontSize, width);
+ m_fontSize, width);
}
else
{
@@ -3208,7 +3229,7 @@ void CEdit::UndoFlush()
for ( i=0 ; i<EDITUNDOMAX ; i++ )
{
delete m_undo[i].text;
- m_undo[i].text = 0;
+ m_undo[i].text = nullptr;
}
m_bUndoForce = true;
@@ -3230,6 +3251,7 @@ void CEdit::UndoMemorize(OperUndo oper)
m_undoOper = oper;
delete m_undo[EDITUNDOMAX-1].text;
+ m_undo[EDITUNDOMAX-1].text = nullptr;
for ( i=EDITUNDOMAX-1 ; i>=1 ; i-- )
{
@@ -3238,7 +3260,7 @@ void CEdit::UndoMemorize(OperUndo oper)
len = m_len;
if ( len == 0 ) len ++;
- m_undo[0].text = (char*)malloc(sizeof(char)*(len+1));
+ m_undo[0].text = new char[len+1];
memcpy(m_undo[0].text, m_text, m_len);
m_undo[0].len = m_len;
@@ -3253,7 +3275,7 @@ bool CEdit::UndoRecall()
{
int i;
- if ( m_undo[0].text == 0 ) return false;
+ if ( m_undo[0].text == nullptr ) return false;
m_len = m_undo[0].len;
memcpy(m_text, m_undo[0].text, m_len);
@@ -3266,7 +3288,7 @@ bool CEdit::UndoRecall()
{
m_undo[i] = m_undo[i+1];
}
- m_undo[EDITUNDOMAX-1].text = 0;
+ m_undo[EDITUNDOMAX-1].text = nullptr;
m_bUndoForce = true;
Justif();
diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp
index a042899..1c62456 100644
--- a/src/ui/interface.cpp
+++ b/src/ui/interface.cpp
@@ -29,6 +29,7 @@ CInterface::CInterface()
m_iMan->AddInstance(CLASS_INTERFACE, this);
m_event = static_cast<CEventQueue *>( m_iMan->SearchInstance(CLASS_EVENT) );
m_engine = static_cast<Gfx::CEngine *>( m_iMan->SearchInstance(CLASS_ENGINE) );
+ m_camera = nullptr;
for (int i = 0; i < MAXCONTROL; i++ )
{
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index 5ed1216..4523b2c 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -56,7 +56,7 @@ const int KEY_TOTAL = 13; // total number of keys redefinable
#else*/
const int KEY_TOTAL = 21; // total number of keys redefinable
-const int WELCOME_LENGTH = 6.0f;
+const int WELCOME_LENGTH = 2.0f;