From 2e21435f432191afa1b0f609daa8ca9d4cde1e93 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 16 Sep 2012 20:00:25 +0200 Subject: Some memory leaks fixed --- src/ui/edit.cpp | 56 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'src/ui/edit.cpp') 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 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=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(); -- cgit v1.2.3-1-g7c22