[dasher: 24/43] Memory fixes identified courtesy of valgrind



commit f920d0a1907b93c1f9b0ee6811c6eebea303e29b
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Thu Apr 21 19:46:51 2011 +0100

    Memory fixes identified courtesy of valgrind

 Src/DasherCore/AlphabetManager.cpp                 |    2 +-
 Src/DasherCore/DasherModel.cpp                     |   17 ++++++++---------
 Src/DasherCore/DasherModel.h                       |    9 ---------
 Src/DasherCore/DasherViewSquare.cpp                |    4 ++--
 .../LanguageModelling/PPMLanguageModel.cpp         |    2 +-
 5 files changed, 12 insertions(+), 22 deletions(-)
---
diff --git a/Src/DasherCore/AlphabetManager.cpp b/Src/DasherCore/AlphabetManager.cpp
index d599eb5..05c73da 100644
--- a/Src/DasherCore/AlphabetManager.cpp
+++ b/Src/DasherCore/AlphabetManager.cpp
@@ -51,7 +51,7 @@ static char THIS_FILE[] = __FILE__;
 #endif
 
 CAlphabetManager::CAlphabetManager(CDasherInterfaceBase *pInterface, CNodeCreationManager *pNCManager, const CAlphInfo *pAlphabet)
-  : m_pFirstGroup(NULL), m_pNCManager(pNCManager), m_pAlphabet(pAlphabet), m_pAlphabetMap(pAlphabet->MakeMap()), m_pInterface(pInterface) {
+  : m_pFirstGroup(NULL), m_pNCManager(pNCManager), m_pAlphabet(pAlphabet), m_pAlphabetMap(pAlphabet->MakeMap()), m_pInterface(pInterface), m_pLastOutput(NULL) {
   //Look for a (single-octet) character not in the alphabet...
   for (char c=33; (c&0x80)==0; c++) {
     string s(&c,1);
diff --git a/Src/DasherCore/DasherModel.cpp b/Src/DasherCore/DasherModel.cpp
index d46c4a1..faeb1db 100644
--- a/Src/DasherCore/DasherModel.cpp
+++ b/Src/DasherCore/DasherModel.cpp
@@ -113,7 +113,7 @@ void CDasherModel::HandleEvent(Dasher::CEvent *pEvent) {
       break;
     case BP_DASHER_PAUSED:
       if(GetBoolParameter(BP_SLOW_START))
-	TriggerSlowdown();
+	m_iStartTime = 0;
       //else, leave m_iStartTime as is - will result in no slow start
       break;
     case BP_GAME_MODE:
@@ -288,18 +288,17 @@ int CDasherModel::GetOffset() {
 
 void CDasherModel::Get_new_root_coords(dasherint X, dasherint Y, dasherint &r1, dasherint &r2, unsigned long iTime) {
   DASHER_ASSERT(m_Root != NULL);
-  if(m_iStartTime == 0)
-    m_iStartTime = iTime;
 
   int iSteps = Steps();
 
-  double dFactor;
+  double dFactor(1.0);
 
-  if(GetBoolParameter(BP_SLOW_START) &&
-     ((iTime - m_iStartTime) < GetLongParameter(LP_SLOW_START_TIME)))
-    dFactor = 0.1 * (1 + 9 * ((iTime - m_iStartTime) / static_cast<double>(GetLongParameter(LP_SLOW_START_TIME))));
-  else
-    dFactor = 1.0;
+  if(GetBoolParameter(BP_SLOW_START)) {
+    if(m_iStartTime == 0)
+      m_iStartTime = iTime;
+    if((iTime - m_iStartTime) < GetLongParameter(LP_SLOW_START_TIME))
+      dFactor = 0.1 * (1 + 9 * ((iTime - m_iStartTime) / static_cast<double>(GetLongParameter(LP_SLOW_START_TIME))));
+  }
 
   iSteps = static_cast<int>(iSteps / dFactor);
 
diff --git a/Src/DasherCore/DasherModel.h b/Src/DasherCore/DasherModel.h
index f1d6d4b..1612f50 100644
--- a/Src/DasherCore/DasherModel.h
+++ b/Src/DasherCore/DasherModel.h
@@ -164,15 +164,6 @@ class Dasher::CDasherModel:public Dasher::CFrameRate, private NoClones
   void LimitRoot(int iMaxWidth);
 
   ///
-  /// Cause Dasher to temporarily slow down (eg as part of automatic
-  /// speed control in n-button dynamic mode).
-  ///
-
-  void TriggerSlowdown() {
-    m_iStartTime = 0;
-  };
-
-  ///
   /// Rebuild the tree of nodes (may reuse the existing ones if !bForce).
   /// @param iLocation offset (cursor position) in attached buffer from which to obtain context
   /// @param pMgr Manager to use to create nodes
diff --git a/Src/DasherCore/DasherViewSquare.cpp b/Src/DasherCore/DasherViewSquare.cpp
index 1088e1b..0cbac99 100644
--- a/Src/DasherCore/DasherViewSquare.cpp
+++ b/Src/DasherCore/DasherViewSquare.cpp
@@ -243,12 +243,12 @@ void CDasherViewSquare::DoDelayedText(CTextString *pText) {
       break;
     }
   }
-  free(pText);
+  delete pText;
 }
 
 CDasherViewSquare::CTextString::~CTextString() {
   for (vector<CTextString *>::iterator it = m_children.begin(); it!=m_children.end(); it++)
-    free(*it);
+    delete *it;
 }
 
 void CDasherViewSquare::TruncateTri(myint x, myint y1, myint y2, myint midy1, myint midy2, int fillColor, int outlineColor, int lineWidth) {
diff --git a/Src/DasherCore/LanguageModelling/PPMLanguageModel.cpp b/Src/DasherCore/LanguageModelling/PPMLanguageModel.cpp
index 1d6d7f6..b520d04 100644
--- a/Src/DasherCore/LanguageModelling/PPMLanguageModel.cpp
+++ b/Src/DasherCore/LanguageModelling/PPMLanguageModel.cpp
@@ -413,7 +413,7 @@ void CAbstractPPM::CPPMnode::AddChild(CPPMnode *pNewChild, int numSymbols) {
       AddChild((CPPMnode *)oldChildren, numSymbols);
     else {
       while (oldSlots-- > 0) if (oldChildren[oldSlots]) AddChild(oldChildren[oldSlots], numSymbols);
-      delete oldChildren;
+      delete[] oldChildren;
     }
     AddChild(pNewChild, numSymbols);
   }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]