Fixing integerencoding memory leaks ...
authorHamed <hamed.gorjiara@gmail.com>
Mon, 4 Sep 2017 20:21:15 +0000 (13:21 -0700)
committerHamed <hamed.gorjiara@gmail.com>
Mon, 4 Sep 2017 20:21:15 +0000 (13:21 -0700)
src/ASTTransform/integerencoding.cc
src/ASTTransform/integerencoding.h
src/ASTTransform/integerencodingrecord.cc
src/ASTTransform/integerencodingrecord.h
src/Encoders/orderencoding.cc
src/Encoders/orderencoding.h
src/Translator/integerencorderresolver.cc
src/csolver.cc

index ab88f20..b52ccf8 100644 (file)
 IntegerEncodingTransform::IntegerEncodingTransform(CSolver *_solver)
        : Transform(_solver)
 {
-       orderIntEncoding = new HashTableOrderIntEncoding();
 }
 
 IntegerEncodingTransform::~IntegerEncodingTransform() {
-       orderIntEncoding->resetanddelete();
 }
 
 void IntegerEncodingTransform::doTransform() {
@@ -30,26 +28,19 @@ void IntegerEncodingTransform::doTransform() {
 }
 
 void IntegerEncodingTransform::integerEncode(Order *currOrder) {
-       IntegerEncodingRecord *encodingRecord = NULL;
-       if (!orderIntEncoding->contains(currOrder)) {
-               encodingRecord = new IntegerEncodingRecord(
-                       solver->createRangeSet(currOrder->set->getType(), 0, (uint64_t) currOrder->set->getSize() - 1));
-               orderIntEncoding->put(currOrder, encodingRecord);
-               currOrder->setOrderEncodingType( INTEGERENCODING );
-       } else {
-               encodingRecord = orderIntEncoding->get(currOrder);
-       }
+       IntegerEncodingRecord *encodingRecord =  new IntegerEncodingRecord(
+               solver->createRangeSet(currOrder->set->getType(), 0, (uint64_t) currOrder->set->getSize() - 1));
+       currOrder->setOrderEncodingType( INTEGERENCODING );
        uint size = currOrder->constraints.getSize();
        for (uint i = 0; i < size; i++) {
-               orderIntegerEncodingSATEncoder(currOrder, currOrder->constraints.get(i));
+               orderIntegerEncodingSATEncoder(currOrder->constraints.get(i), encodingRecord);
        }
        currOrder->setOrderResolver(new IntegerEncOrderResolver(solver, encodingRecord));
        solver->getActiveOrders()->remove(currOrder);
 }
 
 
-void IntegerEncodingTransform::orderIntegerEncodingSATEncoder(Order * currOrder, BooleanOrder *boolOrder) {
-       IntegerEncodingRecord *ierec = orderIntEncoding->get(currOrder);
+void IntegerEncodingTransform::orderIntegerEncodingSATEncoder(BooleanOrder *boolOrder, IntegerEncodingRecord *ierec) {
        //getting two elements and using LT predicate ...
        Element *elem1 = ierec->getOrderIntegerElement(solver, boolOrder->first);
        Element *elem2 = ierec->getOrderIntegerElement(solver, boolOrder->second);
index 8066c2a..805ed0b 100644 (file)
 class IntegerEncodingTransform : public Transform {
 public:
        IntegerEncodingTransform(CSolver *solver);
-       void orderIntegerEncodingSATEncoder(Order * currOrder, BooleanOrder *boolOrder);
+       void orderIntegerEncodingSATEncoder(BooleanOrder *boolOrder, IntegerEncodingRecord *ierec);
        void doTransform();
        void integerEncode(Order *currOrder);
 
        virtual ~IntegerEncodingTransform();
 private:
-       //FIXME:We can remove it, because we don't need it for translating anymore... -HG
-       HashTableOrderIntEncoding *orderIntEncoding;
 };
 
 
index f8690d7..6c8ba2f 100644 (file)
 IntegerEncodingRecord::IntegerEncodingRecord(Set *_set) :
        secondarySet(_set)
 {
-       elementTable = new HashsetOrderElement();
+       elementSet = new HashsetOrderElement();
 }
 
 IntegerEncodingRecord::~IntegerEncodingRecord() {
-       if (elementTable != NULL) {
-               delete elementTable;
+       SetIteratorOrderElement *oiterator = elementSet->iterator();
+       while (oiterator->hasNext()) {
+               OrderElement *oe = oiterator->next();
+               delete oe;
        }
+       delete oiterator;
+       delete elementSet;
 }
 
 Element *IntegerEncodingRecord::getOrderIntegerElement(CSolver *This, uint64_t item, bool create) {
        OrderElement oelement(item, NULL);
-       if ( elementTable->contains(&oelement)) {
-               return elementTable->get(&oelement)->getElement();
+       if ( elementSet->contains(&oelement)) {
+               return elementSet->get(&oelement)->getElement();
        } else if (create) {
                Element *elem = This->getElementVar(secondarySet);
-               elementTable->add(new OrderElement(item, elem));
+               elementSet->add(new OrderElement(item, elem));
                return elem;
        }
        return NULL;
index 556e6c5..39c54ed 100644 (file)
@@ -21,7 +21,7 @@ public:
 
 private:
        Set *secondarySet;
-       HashsetOrderElement *elementTable;
+       HashsetOrderElement *elementSet;
 };
 
 #endif/* INTEGERENCODINGRECORD_H */
index 5e81f14..556554e 100644 (file)
@@ -1,6 +1,15 @@
 #include "orderencoding.h"
+#include "orderresolver.h"
 
 OrderEncoding::OrderEncoding(Order *_order) :
+       resolver(NULL),
        type(ORDER_UNASSIGNED),
-       order(_order) {
+       order(_order)
+{
+}
+
+OrderEncoding::~OrderEncoding(){
+       if(resolver!= NULL){
+               delete resolver;
+       }
 }
index 0792d4a..4b0915a 100644 (file)
@@ -11,7 +11,7 @@ typedef enum OrderEncodingType OrderEncodingType;
 class OrderEncoding {
 public:
        OrderEncoding(Order *order);
-
+       virtual ~OrderEncoding();
        OrderResolver *resolver;
        OrderEncodingType type;
        Order *order;
index a9fb25c..eaf4e47 100644 (file)
@@ -17,6 +17,7 @@ IntegerEncOrderResolver::IntegerEncOrderResolver(CSolver *_solver, IntegerEncodi
 }
 
 IntegerEncOrderResolver::~IntegerEncOrderResolver() {
+       delete ierecord;
 }
 
 
index f52c4eb..d94ddfc 100644 (file)
@@ -400,8 +400,8 @@ int CSolver::solve() {
        long long startTime = getTimeNano();
        computePolarities(this);
 
-//     DecomposeOrderTransform dot(this);
-//     dot.doTransform();
+       DecomposeOrderTransform dot(this);
+       dot.doTransform();
 
        IntegerEncodingTransform iet(this);
        iet.doTransform();