Fix memory issues in bitvector theory, which is now valgrind-clean (mostly resolves...
authorMorgan Deters <mdeters@cs.nyu.edu>
Fri, 7 Nov 2014 22:24:35 +0000 (17:24 -0500)
committerMorgan Deters <mdeters@cs.nyu.edu>
Fri, 7 Nov 2014 22:37:09 +0000 (17:37 -0500)
src/theory/bv/bitblaster_template.h
src/theory/bv/bv_quick_check.cpp
src/theory/bv/bv_quick_check.h
src/theory/bv/lazy_bitblaster.cpp
src/theory/bv/theory_bv.cpp

index ea31e382118236fd416bd6c7112b1e325eea76db..0ff12da955248d2fa1736f89c9b3540d7760a07c 100644 (file)
@@ -143,8 +143,9 @@ class TLazyBitblaster :  public TBitblaster<Node> {
   prop::NullRegistrar* d_nullRegistrar;
   context::Context* d_nullContext;
   // sat solver used for bitblasting and associated CnfStream
-  prop::BVSatSolverInterface*        d_satSolver;
-  prop::CnfStream*                   d_cnfStream;
+  prop::BVSatSolverInterface*         d_satSolver;
+  prop::BVSatSolverInterface::Notify* d_satSolverNotify;
+  prop::CnfStream*                    d_cnfStream;
 
   AssertionList* d_assertedAtoms; /**< context dependent list storing the atoms
                                      currently asserted by the DPLL SAT solver. */
index cc294306a6301bccb37cc484a2bc5a5097b32910..5c67bb3cb7ccca173f8c82a7b2f1451dbc46e7f3 100644 (file)
@@ -25,10 +25,10 @@ using namespace CVC4::theory::bv;
 using namespace CVC4::prop;
 
 BVQuickCheck::BVQuickCheck(const std::string& name, theory::bv::TheoryBV* bv)
-  : d_ctx(new context::Context())
-  , d_bitblaster(new TLazyBitblaster(d_ctx, bv, name, true))
+  : d_ctx()
+  , d_bitblaster(new TLazyBitblaster(&d_ctx, bv, name, true))
   , d_conflict()
-  , d_inConflict(d_ctx, false)
+  , d_inConflict(&d_ctx, false)
 {}
 
 
@@ -100,11 +100,11 @@ bool BVQuickCheck::addAssertion(TNode assertion) {
 
 
 void BVQuickCheck::push() {
-  d_ctx->push();
+  d_ctx.push();
 }
 
 void BVQuickCheck::pop() {
-  d_ctx->pop();
+  d_ctx.pop();
 }
 
 BVQuickCheck::vars_iterator BVQuickCheck::beginVars() {
@@ -130,8 +130,8 @@ void BVQuickCheck::clearSolver() {
 }
 
 void BVQuickCheck::popToZero() {
-  while (d_ctx->getLevel() > 0) {
-    d_ctx->pop();
+  while (d_ctx.getLevel() > 0) {
+    d_ctx.pop();
   }
 }
 
@@ -140,8 +140,8 @@ void BVQuickCheck::collectModelInfo(theory::TheoryModel* model, bool fullModel)
 }
 
 BVQuickCheck::~BVQuickCheck() {
+  clearSolver();
   delete d_bitblaster;
-  delete d_ctx;
 }
 
 QuickXPlain::QuickXPlain(const std::string& name, BVQuickCheck* solver, unsigned long budget)
index 6c32fbb4d77d6a3a15a5706cd04c0a9b3b544754..61d6baf831301847420b05eb50ce3b7f70b54c60 100644 (file)
@@ -39,7 +39,7 @@ class TLazyBitblaster;
 class TheoryBV;
 
 class BVQuickCheck {
-  context::Context* d_ctx;
+  context::Context d_ctx;
   TLazyBitblaster* d_bitblaster;
   Node d_conflict;
   context::CDO<bool> d_inConflict;
index f8927284fd68f3024356baaefb5bdc85b1232902..b74506e4db0870ffb4fe877a3b2b8d785247be7c 100644 (file)
@@ -51,11 +51,11 @@ TLazyBitblaster::TLazyBitblaster(context::Context* c, bv::TheoryBV* bv, const st
                                            d_nullRegistrar,
                                            d_nullContext);
   
-  prop::BVSatSolverInterface::Notify* notify = d_emptyNotify ?
+  d_satSolverNotify = d_emptyNotify ?
     (prop::BVSatSolverInterface::Notify*) new MinisatEmptyNotify() :
     (prop::BVSatSolverInterface::Notify*) new MinisatNotify(d_cnfStream, bv, this);
 
-  d_satSolver->setNotify(notify);
+  d_satSolver->setNotify(d_satSolverNotify);
 }
 
 void TLazyBitblaster::setAbstraction(AbstractionModule* abs) {
@@ -67,6 +67,9 @@ TLazyBitblaster::~TLazyBitblaster() {
   delete d_nullRegistrar;
   delete d_nullContext;
   delete d_satSolver;
+  delete d_satSolverNotify;
+  d_assertedAtoms->deleteSelf();
+  d_explanations->deleteSelf();
 }
 
 
@@ -475,6 +478,7 @@ void TLazyBitblaster::collectModelInfo(TheoryModel* m, bool fullModel) {
 void TLazyBitblaster::clearSolver() {
   Assert (d_ctx->getLevel() == 0); 
   delete d_satSolver;
+  delete d_satSolverNotify;
   delete d_cnfStream;
   d_assertedAtoms->deleteSelf();
   d_assertedAtoms = new(true) context::CDList<prop::SatLiteral>(d_ctx);
@@ -487,11 +491,11 @@ void TLazyBitblaster::clearSolver() {
   // recreate sat solver
   d_satSolver = prop::SatSolverFactory::createMinisat(d_ctx);
   d_cnfStream = new prop::TseitinCnfStream(d_satSolver,
-                                           new prop::NullRegistrar(),
-                                           new context::Context());
+                                           d_nullRegistrar,
+                                           d_nullContext);
 
-  prop::BVSatSolverInterface::Notify* notify = d_emptyNotify ?
+  d_satSolverNotify = d_emptyNotify ?
     (prop::BVSatSolverInterface::Notify*) new MinisatEmptyNotify() :
     (prop::BVSatSolverInterface::Notify*) new MinisatNotify(d_cnfStream, d_bv, this);
-  d_satSolver->setNotify(notify);
+  d_satSolver->setNotify(d_satSolverNotify);
 }
index 91150f663a2fc675c6df1974dd727e20b7532619..99bc764dd9fb9aae1ecf259716418eb63d82d547 100644 (file)
@@ -95,6 +95,7 @@ TheoryBV::~TheoryBV() {
   for (unsigned i = 0; i < d_subtheories.size(); ++i) {
     delete d_subtheories[i];
   }
+  delete d_abstractionModule;
 }
 
 void TheoryBV::setMasterEqualityEngine(eq::EqualityEngine* eq) {