From: bdemsky Date: Fri, 20 Oct 2017 23:13:35 +0000 (-0700) Subject: Fix some memory leaks X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=457ee300c637089a095444672c9d4628faf901e7;p=satune.git Fix some memory leaks --- diff --git a/src/AST/set.cc b/src/AST/set.cc index 7fa1212..0a6e14f 100644 --- a/src/AST/set.cc +++ b/src/AST/set.cc @@ -105,14 +105,22 @@ uint Set::getUnionSize(Set *s) { 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) { - thisValue = getElement(++thisIndex); + thisIndex++; + if (thisIndex < thisSize) + thisValue = getElement(thisIndex); 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++; } } diff --git a/src/ASTAnalyses/Encoding/encodinggraph.cc b/src/ASTAnalyses/Encoding/encodinggraph.cc index 5416ed0..9f9bb04 100644 --- a/src/ASTAnalyses/Encoding/encodinggraph.cc +++ b/src/ASTAnalyses/Encoding/encodinggraph.cc @@ -14,6 +14,12 @@ EncodingGraph::EncodingGraph(CSolver *_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; diff --git a/src/ASTAnalyses/Encoding/encodinggraph.h b/src/ASTAnalyses/Encoding/encodinggraph.h index 0c27e0a..ab9cac6 100644 --- a/src/ASTAnalyses/Encoding/encodinggraph.h +++ b/src/ASTAnalyses/Encoding/encodinggraph.h @@ -7,6 +7,7 @@ class EncodingGraph { public: EncodingGraph(CSolver *solver); + ~EncodingGraph(); void buildGraph(); void encode(); diff --git a/src/ASTAnalyses/Encoding/subgraph.cc b/src/ASTAnalyses/Encoding/subgraph.cc index f2c0de2..8693754 100644 --- a/src/ASTAnalyses/Encoding/subgraph.cc +++ b/src/ASTAnalyses/Encoding/subgraph.cc @@ -9,6 +9,11 @@ EncodingSubGraph::EncodingSubGraph() : maxEncodingVal(0) { } +EncodingSubGraph::~EncodingSubGraph() { + map.resetAndDeleteKeys(); + values.resetAndDelete(); +} + uint hashNodeValuePair(NodeValuePair *nvp) { return (uint) (nvp->value ^ ((uintptr_t)nvp->node)); } diff --git a/src/ASTAnalyses/Encoding/subgraph.h b/src/ASTAnalyses/Encoding/subgraph.h index c9aaa0c..88a1291 100644 --- a/src/ASTAnalyses/Encoding/subgraph.h +++ b/src/ASTAnalyses/Encoding/subgraph.h @@ -37,6 +37,7 @@ typedef Hashtableresetanddelete(); + table->resetAndDeleteVals(); delete table; resetNodeInfoStatusSCC(graph); } @@ -245,7 +245,7 @@ void DFSClearContradictions(CSolver *solver, OrderGraph *graph, Vectorresetanddelete(); + table->resetAndDeleteVals(); delete table; } diff --git a/src/Collections/hashset.h b/src/Collections/hashset.h index 13edbf9..86cbce9 100644 --- a/src/Collections/hashset.h +++ b/src/Collections/hashset.h @@ -117,6 +117,17 @@ public: 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. */ diff --git a/src/Collections/hashtable.h b/src/Collections/hashtable.h index 44b984d..218fb2d 100644 --- a/src/Collections/hashtable.h +++ b/src/Collections/hashtable.h @@ -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) { @@ -146,7 +164,7 @@ public: 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) { diff --git a/src/Translator/orderpairresolver.cc b/src/Translator/orderpairresolver.cc index 6044e06..38c8a76 100644 --- a/src/Translator/orderpairresolver.cc +++ b/src/Translator/orderpairresolver.cc @@ -23,7 +23,7 @@ OrderPairResolver::OrderPairResolver(CSolver *_solver, Order *_order) : OrderPairResolver::~OrderPairResolver() { if (orderPairTable != NULL) { - orderPairTable->resetanddelete(); + orderPairTable->resetAndDeleteVals(); delete orderPairTable; } }