Some memory leaks fixed

dev-ui
Piotr Dziwinski 2012-09-16 20:00:25 +02:00
parent 6a0d150539
commit 2e21435f43
6 changed files with 77 additions and 29 deletions

View File

@ -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(" -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(" -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"); GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n");
return true;
} }
else else
{ {

View File

@ -785,18 +785,20 @@ Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont
data.surface = nullptr; data.surface = nullptr;
SDL_FreeSurface(textSurface);
SDL_FreeSurface(textureSurface);
if (! tex.Valid()) if (! tex.Valid())
{ {
m_error = "Texture create error"; m_error = "Texture create error";
return texture; 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; SDL_FreeSurface(textSurface);
texture.texSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textureSurface->w, textureSurface->h)); SDL_FreeSurface(textureSurface);
texture.charSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textSurface->w, textSurface->h));
return texture; return texture;
} }

View File

@ -642,6 +642,7 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app)
m_selectObject = 0; m_selectObject = 0;
m_infoUsed = 0; m_infoUsed = 0;
m_immediatSatCom = false;
m_beginSatCom = false; m_beginSatCom = false;
m_movieLock = false; m_movieLock = false;
m_satComLock = false; m_satComLock = false;
@ -815,11 +816,32 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app)
//! Destructor of robot application //! Destructor of robot application
CRobotMain::~CRobotMain() CRobotMain::~CRobotMain()
{ {
delete m_movie; delete m_displayText;
delete m_dialog; m_displayText = nullptr;
delete m_short;
delete m_map; delete m_interface;
m_interface = nullptr;
delete m_terrain; 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;
m_map = nullptr;
m_iMan = nullptr; m_iMan = nullptr;
m_app = nullptr; m_app = nullptr;
@ -2707,7 +2729,7 @@ void CRobotMain::HiliteObject(Math::Point pos)
if (obj == nullptr) if (obj == nullptr)
{ {
bool inMap; bool inMap = false;
obj = m_map->DetectMap(pos, inMap); obj = m_map->DetectMap(pos, inMap);
if (obj == nullptr) if (obj == nullptr)
{ {

View File

@ -79,10 +79,13 @@ CEdit::CEdit () : CControl ()
int i; int i;
m_maxChar = 100; 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_len = 0;
m_app = CApplication::GetInstancePointer(); m_app = CApplication::GetInstancePointer();
memset(m_lineOffset, 0, sizeof(int) * EDITLINEMAX);
m_fontType = Gfx::FONT_COURIER; m_fontType = Gfx::FONT_COURIER;
m_scroll = 0; m_scroll = 0;
m_bEdit = true; m_bEdit = true;
@ -102,7 +105,7 @@ CEdit::CEdit () : CControl ()
for ( i=0 ; i<EDITUNDOMAX ; i++ ) for ( i=0 ; i<EDITUNDOMAX ; i++ )
{ {
m_undo[i].text = 0; m_undo[i].text = nullptr;
} }
m_bUndoForce = true; m_bUndoForce = true;
m_undoOper = OPERUNDO_SPEC; m_undoOper = OPERUNDO_SPEC;
@ -119,10 +122,17 @@ CEdit::~CEdit()
for ( i=0 ; i<EDITUNDOMAX ; i++ ) for ( i=0 ; i<EDITUNDOMAX ; i++ )
{ {
delete m_undo[i].text; 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; delete m_scroll;
m_scroll = nullptr;
} }
@ -1472,9 +1482,16 @@ bool CEdit::ReadText(const char *filename, int addSize)
m_cursor2 = 0; m_cursor2 = 0;
FreeImage(); FreeImage();
delete m_text;
m_text = new char[sizeof(char)*(m_maxChar+1)]; if (m_text != nullptr)
buffer = new char[sizeof(char)*(m_maxChar+1)]; 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); fread(buffer, 1, len, file);
if ( m_format.size() > 0 ) if ( m_format.size() > 0 )
@ -1934,15 +1951,18 @@ bool CEdit::WriteText(const char *filename)
void CEdit::SetMaxChar(int max) void CEdit::SetMaxChar(int max)
{ {
m_maxChar = max;
FreeImage(); 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_format.clear();
}
m_len = 0; m_len = 0;
m_cursor1 = 0; m_cursor1 = 0;
@ -3062,8 +3082,9 @@ void CEdit::Justif()
if ( m_format.size() == 0 ) if ( m_format.size() == 0 )
{ {
// TODO check if good // TODO check if good
i += m_engine->GetText()->Justify(m_text+i, m_fontType, i += m_engine->GetText()->Justify(m_text+i, m_fontType,
m_fontSize, width); m_fontSize, width);
} }
else else
{ {
@ -3208,7 +3229,7 @@ void CEdit::UndoFlush()
for ( i=0 ; i<EDITUNDOMAX ; i++ ) for ( i=0 ; i<EDITUNDOMAX ; i++ )
{ {
delete m_undo[i].text; delete m_undo[i].text;
m_undo[i].text = 0; m_undo[i].text = nullptr;
} }
m_bUndoForce = true; m_bUndoForce = true;
@ -3230,6 +3251,7 @@ void CEdit::UndoMemorize(OperUndo oper)
m_undoOper = oper; m_undoOper = oper;
delete m_undo[EDITUNDOMAX-1].text; delete m_undo[EDITUNDOMAX-1].text;
m_undo[EDITUNDOMAX-1].text = nullptr;
for ( i=EDITUNDOMAX-1 ; i>=1 ; i-- ) for ( i=EDITUNDOMAX-1 ; i>=1 ; i-- )
{ {
@ -3238,7 +3260,7 @@ void CEdit::UndoMemorize(OperUndo oper)
len = m_len; len = m_len;
if ( len == 0 ) 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); memcpy(m_undo[0].text, m_text, m_len);
m_undo[0].len = m_len; m_undo[0].len = m_len;
@ -3253,7 +3275,7 @@ bool CEdit::UndoRecall()
{ {
int i; int i;
if ( m_undo[0].text == 0 ) return false; if ( m_undo[0].text == nullptr ) return false;
m_len = m_undo[0].len; m_len = m_undo[0].len;
memcpy(m_text, m_undo[0].text, m_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[i] = m_undo[i+1];
} }
m_undo[EDITUNDOMAX-1].text = 0; m_undo[EDITUNDOMAX-1].text = nullptr;
m_bUndoForce = true; m_bUndoForce = true;
Justif(); Justif();

View File

@ -29,6 +29,7 @@ CInterface::CInterface()
m_iMan->AddInstance(CLASS_INTERFACE, this); m_iMan->AddInstance(CLASS_INTERFACE, this);
m_event = static_cast<CEventQueue *>( m_iMan->SearchInstance(CLASS_EVENT) ); m_event = static_cast<CEventQueue *>( m_iMan->SearchInstance(CLASS_EVENT) );
m_engine = static_cast<Gfx::CEngine *>( m_iMan->SearchInstance(CLASS_ENGINE) ); m_engine = static_cast<Gfx::CEngine *>( m_iMan->SearchInstance(CLASS_ENGINE) );
m_camera = nullptr;
for (int i = 0; i < MAXCONTROL; i++ ) for (int i = 0; i < MAXCONTROL; i++ )
{ {

View File

@ -56,7 +56,7 @@ const int KEY_TOTAL = 13; // total number of keys redefinable
#else*/ #else*/
const int KEY_TOTAL = 21; // total number of keys redefinable const int KEY_TOTAL = 21; // total number of keys redefinable
const int WELCOME_LENGTH = 6.0f; const int WELCOME_LENGTH = 2.0f;