Mostly resolves bug #561 memory leaks, and more.
authorMorgan Deters <mdeters@cs.nyu.edu>
Tue, 29 Apr 2014 23:51:29 +0000 (19:51 -0400)
committerMorgan Deters <mdeters@cs.nyu.edu>
Wed, 30 Apr 2014 01:03:55 +0000 (21:03 -0400)
19 files changed:
src/options/options_template.cpp
src/prop/prop_engine.cpp
src/prop/prop_engine.h
src/prop/registrar.h
src/prop/theory_proxy.h
src/theory/bv/bitblaster.cpp
src/theory/bv/bitblaster.h
src/theory/quantifiers/first_order_model.cpp
src/theory/quantifiers/first_order_model.h
src/theory/quantifiers/full_model_check.h
src/theory/quantifiers/instantiation_engine.cpp
src/theory/quantifiers/instantiation_engine.h
src/theory/quantifiers/model_engine.cpp
src/theory/quantifiers/model_engine.h
src/theory/quantifiers/quant_conflict_find.h
src/theory/quantifiers_engine.cpp
src/theory/theory_model.cpp
src/theory/theory_model.h
src/theory/uf/theory_uf.h

index de44d717ebe194b9e6fef99d60c48c04e9a4d63a..a16e7f899835f1d8bc90696a1257244525845c77 100644 (file)
@@ -557,6 +557,8 @@ ${all_modules_option_handlers}
 
   Debug("options") << "returning " << nonOptions.size() << " non-option arguments." << std::endl;
 
+  free(extra_argv);
+
   return nonOptions;
 }
 
@@ -573,7 +575,7 @@ std::string Options::suggestCommandLineOptions(const std::string& optionName) th
 
 static const char* smtOptions[] = {
   ${all_modules_smt_options},
-#line 577 "${template}"
+#line 579 "${template}"
   NULL
 };/* smtOptions[] */
 
@@ -595,7 +597,7 @@ SExpr Options::getOptions() const throw() {
 
   ${all_modules_get_options}
 
-#line 599 "${template}"
+#line 601 "${template}"
 
   return SExpr(opts);
 }
index 2a2a60391f0e7f16f9f72ea7c1f52b32ae6339b0..cb4a32ee72ec07821ada7c1280bdd2ccec3bf045 100644 (file)
@@ -69,7 +69,9 @@ PropEngine::PropEngine(TheoryEngine* te, DecisionEngine *de, Context* satContext
   d_theoryEngine(te),
   d_decisionEngine(de),
   d_context(satContext),
+  d_theoryProxy(NULL),
   d_satSolver(NULL),
+  d_registrar(NULL),
   d_cnfStream(NULL),
   d_satTimer(*this),
   d_interrupted(false) {
@@ -78,16 +80,17 @@ PropEngine::PropEngine(TheoryEngine* te, DecisionEngine *de, Context* satContext
 
   d_satSolver = SatSolverFactory::createDPLLMinisat(); 
 
-  theory::TheoryRegistrar* registrar = new theory::TheoryRegistrar(d_theoryEngine);
+  d_registrar = new theory::TheoryRegistrar(d_theoryEngine);
   d_cnfStream = new CVC4::prop::TseitinCnfStream
-    (d_satSolver, registrar, 
+    (d_satSolver, d_registrar,
      userContext,
      // fullLitToNode Map = 
      options::threads() > 1 || 
      options::decisionMode() == decision::DECISION_STRATEGY_RELEVANCY
      );
 
-  d_satSolver->initialize(d_context, new TheoryProxy(this, d_theoryEngine, d_decisionEngine, d_context, d_cnfStream));
+  d_theoryProxy = new TheoryProxy(this, d_theoryEngine, d_decisionEngine, d_context, d_cnfStream);
+  d_satSolver->initialize(d_context, d_theoryProxy);
 
   d_decisionEngine->setSatSolver(d_satSolver);
   d_decisionEngine->setCnfStream(d_cnfStream);
@@ -97,7 +100,9 @@ PropEngine::PropEngine(TheoryEngine* te, DecisionEngine *de, Context* satContext
 PropEngine::~PropEngine() {
   Debug("prop") << "Destructing the PropEngine" << endl;
   delete d_cnfStream;
+  delete d_registrar;
   delete d_satSolver;
+  delete d_theoryProxy;
 }
 
 void PropEngine::assertFormula(TNode node) {
index 39182204c7d9b259c52e121e47b311a5f519975e..753890087e06eb48a58ba7505ad56599d1a952c9 100644 (file)
@@ -32,6 +32,10 @@ namespace CVC4 {
 class DecisionEngine;
 class TheoryEngine;
 
+namespace theory {
+  class TheoryRegistrar;
+}/* CVC4::theory namespace */
+
 namespace prop {
 
 class CnfStream;
@@ -132,12 +136,18 @@ class PropEngine {
   /** The context */
   context::Context* d_context;
 
+  /** SAT solver's proxy back to theories; kept around for dtor cleanup */
+  TheoryProxy* d_theoryProxy;
+
   /** The SAT solver proxy */
   DPLLSatSolverInterface* d_satSolver;
 
   /** List of all of the assertions that need to be made */
   std::vector<Node> d_assertionList;
 
+  /** Theory registrar; kept around for destructor cleanup */
+  theory::TheoryRegistrar* d_registrar;
+
   /** The CNF converter in use */
   CnfStream* d_cnfStream;
 
index 0cb3accf1adbee253fca358348e0ec441600f6ab..4fe04f062f717e836a75c14e6300abae258832ae 100644 (file)
@@ -5,7 +5,7 @@
  ** Major contributors: Tim King, Morgan Deters
  ** Minor contributors (to current version): none
  ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2013  New York University and The University of Iowa
+ ** Copyright (c) 2009-2014  New York University and The University of Iowa
  ** See the file COPYING in the top-level source directory for licensing
  ** information.\endverbatim
  **
@@ -32,13 +32,11 @@ public:
 
 };/* class Registrar */
 
-class NullRegistrar: public Registrar {
+class NullRegistrar : public Registrar {
 public:
-  void preRegister(Node n) {};
-
-};/* class Registrar */
-
+  void preRegister(Node n) {}
 
+};/* class NullRegistrar */
 
 }/* CVC4::prop namespace */
 }/* CVC4 namespace */
index f84aecbac1bed3adc54cc50b47edc785e4401aeb..92c81616b86f97ad65fb93b69b8bbcd73dbc2f1e 100644 (file)
@@ -139,6 +139,10 @@ inline TheoryProxy::TheoryProxy(PropEngine* propEngine,
   d_queue(context)
 {}
 
+inline TheoryProxy::~TheoryProxy() {
+  /* nothing to do for now */
+}
+
 }/* CVC4::prop namespace */
 
 }/* CVC4 namespace */
index cbe550f96a06a5c709c66ec46913b9c5ff7e0688..552f3b4481498e30eebfe1e309a464ec817de4a7 100644 (file)
@@ -61,10 +61,12 @@ Bitblaster::Bitblaster(context::Context* c, bv::TheoryBV* bv) :
     d_statistics()
   {
     d_satSolver = prop::SatSolverFactory::createMinisat(c);
-    d_cnfStream = new TseitinCnfStream(d_satSolver, new NullRegistrar(), new Context());
+    d_nullRegistrar = new NullRegistrar();
+    d_nullContext = new Context();
+    d_cnfStream = new TseitinCnfStream(d_satSolver, d_nullRegistrar, d_nullContext);
 
-    MinisatNotify* notify = new MinisatNotify(d_cnfStream, bv);
-    d_satSolver->setNotify(notify);
+    d_notify = new MinisatNotify(d_cnfStream, bv);
+    d_satSolver->setNotify(d_notify);
     // initializing the bit-blasting strategies
     initAtomBBStrategies();
     initTermBBStrategies();
@@ -72,7 +74,10 @@ Bitblaster::Bitblaster(context::Context* c, bv::TheoryBV* bv) :
 
 Bitblaster::~Bitblaster() {
   delete d_cnfStream;
+  delete d_nullContext;
+  delete d_nullRegistrar;
   delete d_satSolver;
+  delete d_notify;
 }
 
 
index 2dc82bddc2ef94238fc43a38ef330a854d86b397..34345086b61804c520307f70071fa2a09c7e15d2 100644 (file)
@@ -37,6 +37,7 @@
 #include "bitblast_strategies.h"
 
 #include "prop/sat_solver.h"
+#include "prop/registrar.h"
 
 namespace CVC4 {
 
@@ -92,8 +93,11 @@ class Bitblaster {
 
   // sat solver used for bitblasting and associated CnfStream
   theory::OutputChannel*             d_bvOutput;
+  MinisatNotify*                     d_notify;
   prop::BVSatSolverInterface*        d_satSolver;
   prop::CnfStream*                   d_cnfStream;
+  prop::NullRegistrar*               d_nullRegistrar;
+  context::Context*                  d_nullContext;
 
   // caches and mappings
   TermDefMap                   d_termCache;
index 098a7819ab72af20082a76e2ad8af42374438487..509c00bb60383d83f32f7578b69f86304c3f5c0e 100644 (file)
@@ -545,6 +545,12 @@ FirstOrderModel(qe, c, name){
 
 }
 
+FirstOrderModelFmc::~FirstOrderModelFmc() {
+  for(std::map<Node, Def*>::iterator i = d_models.begin(); i != d_models.end(); ++i) {
+    delete (*i).second;
+  }
+}
+
 Node FirstOrderModelFmc::getUsedRepresentative(Node n, bool strict) {
   //Assert( fm->hasTerm(n) );
   TypeNode tn = n.getType();
index 2ac9dadcfdb2907bbff13391802f5a0baffea1ed..63d8ffcce23f6a600c8f25a580c4a5347ab60f0d 100644 (file)
@@ -26,14 +26,16 @@ namespace theory {
 
 class QuantifiersEngine;
 
-namespace quantifiers{
+namespace quantifiers {
 
 class TermDb;
 
 class FirstOrderModelIG;
+
 namespace fmcheck {
   class FirstOrderModelFmc;
-}
+}/* CVC4::theory::quantifiers::fmcheck namespace */
+
 class FirstOrderModelQInt;
 
 struct IsStarAttributeId {};
@@ -69,7 +71,7 @@ public: //for Theory Quantifiers:
   virtual void processInitializeQuantifier( Node q ) {}
 public:
   FirstOrderModel(QuantifiersEngine * qe, context::Context* c, std::string name );
-  virtual ~FirstOrderModel(){}
+  virtual ~FirstOrderModel() {}
   virtual FirstOrderModelIG * asFirstOrderModelIG() { return NULL; }
   virtual fmcheck::FirstOrderModelFmc * asFirstOrderModelFmc() { return NULL; }
   virtual FirstOrderModelQInt * asFirstOrderModelQInt() { return NULL; }
@@ -134,7 +136,7 @@ private:
   void clearEvalFailed( int index );
   std::map< Node, bool > d_eval_failed;
   std::map< int, std::vector< Node > > d_eval_failed_lits;
-};
+};/* class FirstOrderModelIG */
 
 
 namespace fmcheck {
@@ -156,6 +158,7 @@ private:
   void processInitializeModelForTerm(Node n);
 public:
   FirstOrderModelFmc(QuantifiersEngine * qe, context::Context* c, std::string name);
+  virtual ~FirstOrderModelFmc();
   FirstOrderModelFmc * asFirstOrderModelFmc() { return this; }
   // initialize the model
   void processInitialize( bool ispre );
@@ -169,9 +172,9 @@ public:
   bool isInterval(Node n);
   Node getInterval( Node lb, Node ub );
   bool isInRange( Node v, Node i );
-};
+};/* class FirstOrderModelFmc */
 
-}
+}/* CVC4::theory::quantifiers::fmcheck namespace */
 
 
 class QIntDef;
@@ -215,7 +218,7 @@ public:
   unsigned getOrderedNumVars( Node q );
   TypeNode getOrderedVarType( Node q, int i );
   int getOrderedVarNumToVarNum( Node q, int i );
-};
+};/* class FirstOrderModelQInt */
 
 
 }/* CVC4::theory::quantifiers namespace */
index db5abb01ed9cea926aed1c76dd88866dd43c36e9..372868ad7c4fac0232f68853dd1dc321468ba0b1 100644 (file)
@@ -5,7 +5,7 @@
  ** Major contributors: Morgan Deters
  ** Minor contributors (to current version): none
  ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2013  New York University and The University of Iowa
+ ** Copyright (c) 2009-2014  New York University and The University of Iowa
  ** See the file COPYING in the top-level source directory for licensing
  ** information.\endverbatim
  **
@@ -14,8 +14,8 @@
 
 #include "cvc4_private.h"
 
-#ifndef FULL_MODEL_CHECK
-#define FULL_MODEL_CHECK
+#ifndef __CVC4__THEORY__QUANTIFIERS__FULL_MODEL_CHECK_H
+#define __CVC4__THEORY__QUANTIFIERS__FULL_MODEL_CHECK_H
 
 #include "theory/quantifiers/model_builder.h"
 #include "theory/quantifiers/first_order_model.h"
@@ -45,7 +45,7 @@ public:
 
   void collectIndices(Node c, int index, std::vector< int >& indices );
   bool isComplete(FirstOrderModelFmc * m, Node c, int index);
-};
+};/* class EntryTrie */
 
 
 class Def
@@ -79,7 +79,7 @@ public:
   int getGeneralizationIndex( FirstOrderModelFmc * m, std::vector<Node>& inst );
   void simplify( FullModelChecker * mc, FirstOrderModelFmc * m );
   void debugPrint(const char * tr, Node op, FullModelChecker * m);
-};
+};/* class Def */
 
 
 class FullModelChecker : public QModelBuilder
@@ -151,11 +151,11 @@ public:
   Node getCurrentUfModelValue( FirstOrderModelFmc* fm, Node n, std::vector< Node > & args, bool partial );
 
   bool useSimpleModels();
-};
+};/* class FullModelChecker */
 
-}
-}
-}
-}
+}/* CVC4::theory::quantifiers::fmcheck namespace */
+}/* CVC4::theory::quantifiers namespace */
+}/* CVC4::theory namespace */
+}/* CVC4 namespace */
 
-#endif
+#endif /* __CVC4__THEORY__QUANTIFIERS__FULL_MODEL_CHECK_H */
index e5705882a5ddc1dfc1f499ed2021da9b3fecb2d7..c8a08dad970a34c89a7d430655ae880311c8c1a6 100644 (file)
@@ -31,10 +31,15 @@ using namespace CVC4::theory::quantifiers;
 using namespace CVC4::theory::inst;
 
 InstantiationEngine::InstantiationEngine( QuantifiersEngine* qe, bool setIncomplete ) :
-QuantifiersModule( qe ), d_setIncomplete( setIncomplete ), d_ierCounter( 0 ), d_performCheck( false ){
+QuantifiersModule( qe ), d_isup(NULL), d_i_ag(NULL), d_setIncomplete( setIncomplete ), d_ierCounter( 0 ), d_performCheck( false ){
 
 }
 
+InstantiationEngine::~InstantiationEngine() {
+  delete d_i_ag;
+  delete d_isup;
+}
+
 void InstantiationEngine::finishInit(){
   //for UF terms
   if( !options::finiteModelFind() || options::fmfInstEngine() ){
@@ -48,14 +53,14 @@ void InstantiationEngine::finishInit(){
     }else{
       d_isup = NULL;
     }
-    InstStrategyAutoGenTriggers* i_ag = new InstStrategyAutoGenTriggers( d_quantEngine, Trigger::TS_ALL, 3 );
-    i_ag->setGenerateAdditional( true );
-    addInstStrategy( i_ag );
+    d_i_ag = new InstStrategyAutoGenTriggers( d_quantEngine, Trigger::TS_ALL, 3 );
+    d_i_ag->setGenerateAdditional( true );
+    addInstStrategy( d_i_ag );
     //addInstStrategy( new InstStrategyAddFailSplits( this, ie ) );
     if( !options::finiteModelFind() && options::fullSaturateQuant() ){
       addInstStrategy( new InstStrategyFreeVariable( d_quantEngine ) );
     }
-    //d_isup->setPriorityOver( i_ag );
+    //d_isup->setPriorityOver( d_i_ag );
     //d_isup->setPriorityOver( i_agm );
     //i_ag->setPriorityOver( i_agm );
   }
index 394d53d4229176fd979e59c37432ac6d0f5933d5..53777d3627fbebd7ccc64cb621c3c8856bd5d81f 100644 (file)
@@ -25,6 +25,7 @@ namespace theory {
 namespace quantifiers {
 
 class InstStrategyUserPatterns;
+class InstStrategyAutoGenTriggers;
 
 /** instantiation strategy class */
 class InstStrategy {
@@ -79,6 +80,8 @@ private:
   std::map< InstStrategy*, bool > d_instStrategyActive;
   /** user-pattern instantiation strategy */
   InstStrategyUserPatterns* d_isup;
+  /** auto gen triggers; only kept for destructor cleanup */
+  InstStrategyAutoGenTriggers* d_i_ag;
   /** is instantiation strategy active */
   bool isActiveStrategy( InstStrategy* is ) {
     return d_instStrategyActive.find( is )!=d_instStrategyActive.end() && d_instStrategyActive[is];
@@ -123,7 +126,7 @@ private:
   void debugSat( int reason );
 public:
   InstantiationEngine( QuantifiersEngine* qe, bool setIncomplete = true );
-  ~InstantiationEngine(){}
+  ~InstantiationEngine();
   /** initialize */
   void finishInit();
 
index d7b074accc98ce811b592d436a26d6b9c8b156eb..3a4879b427405387a180719df3bc1170843924dc 100644 (file)
@@ -53,6 +53,10 @@ QuantifiersModule( qe ){
   }
 }
 
+ModelEngine::~ModelEngine() {
+  delete d_builder;
+}
+
 void ModelEngine::check( Theory::Effort e ){
   if( e==Theory::EFFORT_LAST_CALL && !d_quantEngine->hasAddedLemma() ){
     int addedLemmas = 0;
index 3b34f750433c1a977b59054144d408adf7461793..79bdcd19b6449dc8f5d69b4a9fb1d19fc4647f7f 100644 (file)
@@ -48,7 +48,7 @@ private:
   int d_totalLemmas;
 public:
   ModelEngine( context::Context* c, QuantifiersEngine* qe );
-  ~ModelEngine(){}
+  virtual ~ModelEngine();
   //get the builder
   QModelBuilder* getModelBuilder() { return d_builder; }
 public:
index 8a0d956ac7f000b3080303ee23ef523405aca5d9..71e9676534ff8d4f9f57e554fef78cf305f0eecc 100755 (executable)
@@ -125,6 +125,7 @@ private: //for completing match
   std::vector< int > d_una_eqc_count;\r
 public:\r
   QuantInfo() : d_mg( NULL ) {}\r
+  ~QuantInfo() { delete d_mg; }\r
   std::vector< TNode > d_vars;\r
   std::map< TNode, int > d_var_num;\r
   std::map< TNode, bool > d_nbeneathQuant;\r
index be011cdb6b340f1090e096aea1d0b51e2381942b..b79c0da699eae17d6288818f38f4a59c9d7fa7db 100644 (file)
@@ -113,11 +113,20 @@ d_lemmas_produced_c(u){
 }
 
 QuantifiersEngine::~QuantifiersEngine(){
+  delete d_rr_engine;
+  delete d_bint;
   delete d_model_engine;
   delete d_inst_engine;
+  delete d_qcf;
+  delete d_quant_rel;
+  delete d_rel_dom;
   delete d_model;
+  delete d_tr_trie;
   delete d_term_db;
   delete d_eq_query;
+  for(std::map< Node, QuantPhaseReq* >::iterator i = d_phase_reqs.begin(); i != d_phase_reqs.end(); ++i) {
+    delete (*i).second;
+  }
 }
 
 EqualityQueryQuantifiersEngine* QuantifiersEngine::getEqualityQuery() {
index f207bdb8eb923c511b17a3f6c396d12a88a2435b..7187a373f22255d3355d1b2fd6e67f9b2e771f96 100644 (file)
@@ -27,7 +27,7 @@ using namespace CVC4::kind;
 using namespace CVC4::context;
 using namespace CVC4::theory;
 
-TheoryModel::TheoryModel( context::Context* c, std::string name, bool enableFuncModels) :
+TheoryModel::TheoryModel(context::Context* c, std::string name, bool enableFuncModels) :
   d_substitutions(c, false), d_modelBuilt(c, false), d_enableFuncModels(enableFuncModels)
 {
   d_true = NodeManager::currentNM()->mkConst( true );
@@ -46,6 +46,12 @@ TheoryModel::TheoryModel( context::Context* c, std::string name, bool enableFunc
   d_eeContext->push();
 }
 
+TheoryModel::~TheoryModel() {
+  d_eeContext->pop();
+  delete d_equalityEngine;
+  delete d_eeContext;
+}
+
 void TheoryModel::reset(){
   d_reps.clear();
   d_rep_set.clear();
index 598db2683c82e9308395965a92f932c0b313810e..65b09befc8170a4638b1d6a88a664d83fb360f54 100644 (file)
@@ -38,7 +38,7 @@ protected:
   SubstitutionMap d_substitutions;
 public:
   TheoryModel(context::Context* c, std::string name, bool enableFuncModels);
-  virtual ~TheoryModel(){}
+  virtual ~TheoryModel();
 
   /** special local context for our equalityEngine so we can clear it independently of search context */
   context::Context* d_eeContext;
index b9ca171541e4b619362846044fd1f72a0ddedd07..938fc4f6731c1e020c9e092504fcd14da9d162b3 100644 (file)
@@ -183,6 +183,7 @@ public:
         ++i) {
       delete i->second;
     }
+    delete d_thss;
   }
 
   void setMasterEqualityEngine(eq::EqualityEngine* eq);