[opengtl-commits] [320] fix leaks

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 320
Author:   cyrille
Date:     2008-08-29 01:03:27 +0200 (Fri, 29 Aug 2008)

Log Message:
-----------
fix leaks

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Utils_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-08-28 23:03:27 UTC (rev 320)
@@ -30,6 +30,7 @@
 #include "../Visitor_p.h"
 #include "../Type.h"
 #include "../Type_p.h"
+#include "../Utils_p.h"
 
 using namespace GTLCore::AST;
 
@@ -90,6 +91,11 @@
 {
 }
 
+StructAccessorExpression::~StructAccessorExpression()
+{
+  delete m_parent;
+}
+
 llvm::Value* StructAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
 {
   GTL_DEBUG("StructAccessorExpression::pointer");
@@ -120,6 +126,12 @@
 {
 }
 
+ArrayAccessorExpression::~ArrayAccessorExpression()
+{
+  delete m_parent;
+  delete m_index;
+}
+
 llvm::Value* ArrayAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const
 {
   GTL_DEBUG("ArrayAccessorExpression::pointer");
@@ -201,6 +213,12 @@
   m_arguments.push_front( _parent );
 }
 
+FunctionMemberAccessorExpression::~FunctionMemberAccessorExpression()
+{
+  deleteAll( m_arguments );
+// don't delete m_parent since it's part of the arguments list
+}
+
 bool FunctionMemberAccessorExpression::isConstant() const
 {
   return true;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-08-28 23:03:27 UTC (rev 320)
@@ -48,6 +48,7 @@
     class StructAccessorExpression : public AccessorExpression {
       public:
         StructAccessorExpression(AccessorExpression* _parent, int _index);
+        ~StructAccessorExpression();
         virtual bool isConstant() const;
         virtual const GTLCore::Type* type() const;
       public:
@@ -61,6 +62,7 @@
     class ArrayAccessorExpression : public AccessorExpression {
       public:
         ArrayAccessorExpression(AccessorExpression * _parent, Expression* _index);
+        ~ArrayAccessorExpression();
         virtual bool isConstant() const;
         virtual const GTLCore::Type* type() const;
       public:
@@ -89,6 +91,7 @@
         FunctionMemberAccessorExpression( AccessorExpression * _parent, 
                                           const Type::StructFunctionMember* _member,
                                           const std::list<AST::Expression*>& _arguments );
+        ~FunctionMemberAccessorExpression();
         virtual bool isConstant() const;
         virtual const GTLCore::Type* type() const;
       public:

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp	2008-08-28 23:03:27 UTC (rev 320)
@@ -22,6 +22,8 @@
 #include <list>
 #include <map>
 
+#include "AST/ConvertExpression.h"
+
 using namespace GTLCore;
 
 struct ConvertExpressionFactory::Private {
@@ -64,8 +66,15 @@
   delete d;
 }
 
-AST::ConvertExpression* ConvertCenter::createConvertExpression( AST::Expression* value, const GTLCore::Type* _dstType ) const
+AST::ConvertExpression* ConvertCenter::createConvertExpression( AST::Expression* _value, const GTLCore::Type* _dstType ) const
 {
+  for( std::list< ConvertExpressionFactory* >::iterator it = d->factories.begin(); it != d->factories.end(); ++it)
+  {
+    if( (*it)->srcType() == _value->type() and (*it)->dstType() == _dstType)
+    {
+      return (*it)->create( _value );
+    }
+  }
   return 0;
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-08-28 23:03:27 UTC (rev 320)
@@ -44,6 +44,7 @@
 #include "Debug.h"
 #include "Token_p.h"
 #include "Function_p.h"
+#include "Utils_p.h"
 
 #include "TypeManager.h"
 #include "TypeManager_p.h"
@@ -291,6 +292,7 @@
       }
     } else {
       // An error has occured
+      reportError("Parse error while parsing constant", d->currentToken );
       return 0;
     }
   } else if( d->currentToken.isUnaryOperator() )
@@ -634,6 +636,7 @@
               AST::Expression* initialiser = 0;
               std::list<AST::Expression*> memberArraySize = parseArraySize(true);
               ptype = d->compiler->typeManager()->getArray( ptype, memberArraySize.size() );
+              deleteAll( memberArraySize);
               if( d->currentToken.type == Token::EQUAL )
               {
                 getNextToken();

Modified: trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp	2008-08-28 23:03:27 UTC (rev 320)
@@ -33,6 +33,10 @@
 
 TypeManager::~TypeManager()
 {
+  for( std::map< GTLCore::String, const GTLCore::Type*>::iterator it = d->knownTypes.begin(); it != d->knownTypes.end(); ++it)
+  {
+    delete it->second;
+  }
   delete d;
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-08-28 23:03:27 UTC (rev 320)
@@ -23,6 +23,7 @@
 #include "Function.h"
 #include "Parameter.h"
 #include "ScopedName.h"
+#include "Visitor_p.h"
 
 using namespace GTLCore;
 
@@ -75,7 +76,7 @@
   return d->function;
 }
 
-Type::Private::Private( Type::DataType _dataType) : dataType(_dataType), m_visitor(0)
+Type::Private::Private( Type::DataType _dataType) : dataType(_dataType), structDataMembers(0), structFunctionMembers(0), structPrivateFunctionMembers(0), m_visitor(0)
 {
   switch( _dataType )
   {
@@ -119,6 +120,13 @@
   }
 }
 
+Type::Private::~Private()
+{
+  delete structDataMembers;
+  delete structFunctionMembers;
+  delete structPrivateFunctionMembers;
+}
+
 const llvm::Type * Type::Private::pointerType() const
 {
   return llvm::PointerType::get( type(), 0);

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-08-28 23:03:27 UTC (rev 320)
@@ -73,8 +73,9 @@
   struct Type::Private {
     friend class Type;
     public:
-      Private() : m_type(0), m_visitor(0) {}
+      Private() : m_type(0), structDataMembers(0), structFunctionMembers(0), structPrivateFunctionMembers(0), m_visitor(0) {}
       Private( Type::DataType _dataType );
+      ~Private();
       const llvm::Type * type() const { return m_type; }
       /**
        * @return a pointer version of the type a.k.a. llvm::PointerType::get( type(), 0)

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Utils_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Utils_p.h	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Utils_p.h	2008-08-28 23:03:27 UTC (rev 320)
@@ -24,7 +24,7 @@
 
   /**
    * @internal
-   * Delete all pointers of a list.
+   * Delete all pointers of a list or a vector.
    * @ingroup GTLCore
    */
   template<class _Type_>
@@ -35,6 +35,19 @@
       delete *it;
     }
   }
+  /**
+   * @internal
+   * Delete all second members of a map
+   * @ingroup GTLCore
+   */
+  template<class _Type_>
+  void deleteAllSecondMember( _Type_& map )
+  {
+    for( typename _Type_::iterator it = map.begin(); it != map.end(); ++it)
+    {
+      delete it->second;
+    }
+  }
 
 }
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-08-19 10:07:57 UTC (rev 319)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-08-28 23:03:27 UTC (rev 320)
@@ -318,7 +318,7 @@
     llvm::Value* ptrToData = llvm::GetElementPtrInst::Create( _pointer, indexes.begin(), indexes.end(), "", endBodyBlock);
     new llvm::FreeInst( new llvm::LoadInst( ptrToData, "", endBodyBlock ), endBodyBlock );
     // Create the for statement
-    return CodeGenerator::createIterationForStatement(
+    llvm::BasicBlock*  afterBlock = CodeGenerator::createIterationForStatement(
                     _generationContext,
                     _currentBlock,
                     index,
@@ -326,6 +326,8 @@
                     Type::Integer32,
                     bodyBlock,
                     endBodyBlock );
+    delete index;
+    return afterBlock;
 }
 
 //--------- VectorVisitor ---------///


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/