Fix some memory leaks
authorbdemsky <bdemsky@uci.edu>
Fri, 20 Oct 2017 23:13:35 +0000 (16:13 -0700)
committerbdemsky <bdemsky@uci.edu>
Fri, 20 Oct 2017 23:13:35 +0000 (16:13 -0700)
src/AST/set.cc
src/ASTAnalyses/Encoding/encodinggraph.cc
src/ASTAnalyses/Encoding/encodinggraph.h
src/ASTAnalyses/Encoding/subgraph.cc
src/ASTAnalyses/Encoding/subgraph.h
src/ASTAnalyses/Order/orderanalysis.cc
src/Collections/hashset.h
src/Collections/hashtable.h
src/Translator/orderpairresolver.cc

index 7fa1212197030e1761c7bfefd2bb00f59a7ad50e..0a6e14f41a95dfdf439fa3ef06153083f67ccff2 100644 (file)
@@ -105,14 +105,22 @@ uint Set::getUnionSize(Set *s) {
        uint64_t thisValue = getElement(thisIndex);
        while (thisIndex < thisSize && sIndex < sSize) {
                if (sValue < thisValue) {
        uint64_t thisValue = getElement(thisIndex);
        while (thisIndex < thisSize && sIndex < sSize) {
                if (sValue < thisValue) {
-                       sValue = s->getElement(++sIndex);
+                       sIndex++;
+                       if (sIndex < sSize)
+                               sValue = s->getElement(sIndex);
                        sum++;
                } else if (thisValue < sValue) {
                        sum++;
                } else if (thisValue < sValue) {
-                       thisValue = getElement(++thisIndex);
+                       thisIndex++;
+                       if (thisIndex < thisSize)
+                               thisValue = getElement(thisIndex);
                        sum++;
                } else {
                        sum++;
                } else {
-                       thisValue = getElement(++thisIndex);
-                       sValue = s->getElement(++sIndex);
+                       thisIndex++;
+                       sIndex++;
+                       if (sIndex < sSize)
+                               sValue = s->getElement(sIndex);
+                       if (thisIndex < thisSize)
+                               thisValue = getElement(thisIndex);
                        sum++;
                }
        }
                        sum++;
                }
        }
index 5416ed0e2d7778444bff22640de8f127dd6ef187..9f9bb047a1908bda9858b14a96087225ab9f5072 100644 (file)
@@ -14,6 +14,12 @@ EncodingGraph::EncodingGraph(CSolver *_solver) :
        solver(_solver) {
 }
 
        solver(_solver) {
 }
 
+EncodingGraph::~EncodingGraph() {
+       subgraphs.resetAndDelete();
+       encodingMap.resetAndDeleteVals();
+       edgeMap.resetAndDeleteVals();
+}
+
 int sortEncodingEdge(const void *p1, const void *p2) {
        const EncodingEdge *e1 = *(const EncodingEdge **) p1;
        const EncodingEdge *e2 = *(const EncodingEdge **) p2;
 int sortEncodingEdge(const void *p1, const void *p2) {
        const EncodingEdge *e1 = *(const EncodingEdge **) p1;
        const EncodingEdge *e2 = *(const EncodingEdge **) p2;
index 0c27e0af8495047eaf275adb9b7781a289d4afd9..ab9cac6cc3621e5d1f340cac4e95305c807f390a 100644 (file)
@@ -7,6 +7,7 @@
 class EncodingGraph {
 public:
        EncodingGraph(CSolver *solver);
 class EncodingGraph {
 public:
        EncodingGraph(CSolver *solver);
+       ~EncodingGraph();
        void buildGraph();
        void encode();
 
        void buildGraph();
        void encode();
 
index f2c0de2371beec9a4cfd5f9dbba6c0551c2a1a27..86937549fe578070a78914c0a27f9e9307e08b16 100644 (file)
@@ -9,6 +9,11 @@ EncodingSubGraph::EncodingSubGraph() :
        maxEncodingVal(0) {
 }
 
        maxEncodingVal(0) {
 }
 
+EncodingSubGraph::~EncodingSubGraph() {
+       map.resetAndDeleteKeys();
+       values.resetAndDelete();
+}
+
 uint hashNodeValuePair(NodeValuePair *nvp) {
        return (uint) (nvp->value ^ ((uintptr_t)nvp->node));
 }
 uint hashNodeValuePair(NodeValuePair *nvp) {
        return (uint) (nvp->value ^ ((uintptr_t)nvp->node));
 }
index c9aaa0cd6d63813aaf90f6619e58ad12b0953193..88a129129a8c3de1e8b005469727ba1656218e61 100644 (file)
@@ -37,6 +37,7 @@ typedef Hashtable<NodeValuePair *, EncodingValue *, uintptr_t, 0, hashNodeValueP
 class EncodingSubGraph {
 public:
        EncodingSubGraph();
 class EncodingSubGraph {
 public:
        EncodingSubGraph();
+       ~EncodingSubGraph();
        void addNode(EncodingNode *n);
        SetIteratorEncodingNode *nodeIterator();
        void encode();
        void addNode(EncodingNode *n);
        SetIteratorEncodingNode *nodeIterator();
        void encode();
index 3d829c94b5e57ed59676071fb63d57634f3c82f0..13e26c07eca66a0cfa32c20b115340e0bbf07085 100644 (file)
@@ -155,7 +155,7 @@ void completePartialOrderGraph(OrderGraph *graph) {
                }
        }
 
                }
        }
 
-       table->resetanddelete();
+       table->resetAndDeleteVals();
        delete table;
        resetNodeInfoStatusSCC(graph);
 }
        delete table;
        resetNodeInfoStatusSCC(graph);
 }
@@ -245,7 +245,7 @@ void DFSClearContradictions(CSolver *solver, OrderGraph *graph, Vector<OrderNode
                }
        }
 
                }
        }
 
-       table->resetanddelete();
+       table->resetAndDeleteVals();
        delete table;
 }
 
        delete table;
 }
 
index 13edbf95895e589d88fb4d548e575e7cf677408c..86cbce90530034c52b19364a68426b1588dc521a 100644 (file)
@@ -117,6 +117,17 @@ public:
                table->reset();
        }
 
                table->reset();
        }
 
+       void resetAndDelete() {
+               Linknode<_Key> *tmp = list;
+               while (tmp != NULL) {
+                       Linknode<_Key> *tmpnext = tmp->next;
+                       ourfree(tmp);
+                       tmp = tmpnext;
+               }
+               list = tail = NULL;
+               table->resetAndDeleteKeys();
+       }
+
        /** @brief Adds a new key to the hashset.  Returns false if the key
         *  is already present. */
 
        /** @brief Adds a new key to the hashset.  Returns false if the key
         *  is already present. */
 
index 44b984daafea43a9b9ab943ea23d04dc025ea531..218fb2d6d17f653004baaeecdef7cf59dee549b1 100644 (file)
@@ -126,7 +126,25 @@ public:
                }
        }
 
                }
        }
 
-       void resetanddelete() {
+       void resetAndDeleteKeys() {
+               for (unsigned int i = 0; i < capacity; i++) {
+                       struct Hashlistnode<_Key, _Val> *bin = &table[i];
+                       if (bin->key != NULL) {
+                               delete bin->key;
+                               bin->key = NULL;
+                               if (bin->val != NULL) {
+                                       bin->val = NULL;
+                               }
+                       }
+               }
+               if (zero) {
+                       ourfree(zero);
+                       zero = NULL;
+               }
+               size = 0;
+       }
+
+       void resetAndDeleteVals() {
                for (unsigned int i = 0; i < capacity; i++) {
                        struct Hashlistnode<_Key, _Val> *bin = &table[i];
                        if (bin->key != NULL) {
                for (unsigned int i = 0; i < capacity; i++) {
                        struct Hashlistnode<_Key, _Val> *bin = &table[i];
                        if (bin->key != NULL) {
@@ -146,7 +164,7 @@ public:
                size = 0;
        }
 
                size = 0;
        }
 
-       void resetandfree() {
+       void resetAndFreeVals() {
                for (unsigned int i = 0; i < capacity; i++) {
                        struct Hashlistnode<_Key, _Val> *bin = &table[i];
                        if (bin->key != NULL) {
                for (unsigned int i = 0; i < capacity; i++) {
                        struct Hashlistnode<_Key, _Val> *bin = &table[i];
                        if (bin->key != NULL) {
index 6044e067c8b7f9140e1f2ca9501cd3b3ea2dc120..38c8a761824b0139fc0d3bcdda376486bc2f47a9 100644 (file)
@@ -23,7 +23,7 @@ OrderPairResolver::OrderPairResolver(CSolver *_solver, Order *_order) :
 
 OrderPairResolver::~OrderPairResolver() {
        if (orderPairTable != NULL) {
 
 OrderPairResolver::~OrderPairResolver() {
        if (orderPairTable != NULL) {
-               orderPairTable->resetanddelete();
+               orderPairTable->resetAndDeleteVals();
                delete orderPairTable;
        }
 }
                delete orderPairTable;
        }
 }