From 4b90c5b6a1f5f3a637dc38fc4fd94ce3c00d154a Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 22 Aug 2017 23:01:42 -0700 Subject: [PATCH] Fix memory bugs --- src/AST/order.c | 4 ++++ src/Collections/hashtable.h | 6 +++--- src/Encoders/orderencoder.c | 2 ++ src/Encoders/ordergraph.c | 4 +++- src/Test/ordertest.c | 9 ++------- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/AST/order.c b/src/AST/order.c index 3e0f73e..b5840da 100644 --- a/src/AST/order.c +++ b/src/AST/order.c @@ -2,6 +2,7 @@ #include "structs.h" #include "set.h" #include "boolean.h" +#include "ordergraph.h" Order *allocOrder(OrderType type, Set *set) { Order *This = (Order *)ourmalloc(sizeof(Order)); @@ -33,5 +34,8 @@ void deleteOrder(Order *This) { resetAndDeleteHashTableOrderPair(This->orderPairTable); deleteHashTableOrderPair(This->orderPairTable); } + if (This->graph != NULL) { + deleteOrderGraph(This->graph); + } ourfree(This); } diff --git a/src/Collections/hashtable.h b/src/Collections/hashtable.h index 15f69af..59e7ece 100644 --- a/src/Collections/hashtable.h +++ b/src/Collections/hashtable.h @@ -103,9 +103,9 @@ ourfree(tab->zero); \ tab->zero = NULL; \ } \ - tab->size = 0; \ - } \ - \ + tab->size = 0; \ + } \ + \ void reset ## Name(HashTable ## Name * tab) { \ memset(tab->table, 0, tab->capacity * sizeof(struct hashlistnode ## Name)); \ if (tab->zero) { \ diff --git a/src/Encoders/orderencoder.c b/src/Encoders/orderencoder.c index a43d39d..00c6468 100644 --- a/src/Encoders/orderencoder.c +++ b/src/Encoders/orderencoder.c @@ -160,6 +160,7 @@ void completePartialOrderGraph(OrderGraph *graph) { } resetAndDeleteHashTableNodeToNodeSet(table); + deleteHashTableNodeToNodeSet(table); resetNodeInfoStatusSCC(graph); deleteVectorArrayOrderNode(&sccNodes); deleteVectorArrayOrderNode(&finishNodes); @@ -250,6 +251,7 @@ void DFSClearContradictions(CSolver *solver, OrderGraph *graph, VectorOrderNode } resetAndDeleteHashTableNodeToNodeSet(table); + deleteHashTableNodeToNodeSet(table); } /* This function finds edges that would form a cycle with must edges diff --git a/src/Encoders/ordergraph.c b/src/Encoders/ordergraph.c index f920076..32e1350 100644 --- a/src/Encoders/ordergraph.c +++ b/src/Encoders/ordergraph.c @@ -83,7 +83,7 @@ void addMustOrderEdge(OrderGraph *graph, OrderNode *node1, OrderNode *node2, Boo _1to2->polPos = true; addNewOutgoingEdge(node1, _1to2); addNewIncomingEdge(node2, _1to2); - if (constr->base.polarity == BV_MUSTBETRUE) + if (constr->base.boolVal == BV_MUSTBETRUE) break; } case BV_MUSTBEFALSE: { @@ -176,5 +176,7 @@ void deleteOrderGraph(OrderGraph *graph) { deleteOrderEdge(edge); } deleteIterOrderEdge(eiterator); + deleteHashSetOrderNode(graph->nodes); + deleteHashSetOrderEdge(graph->edges); ourfree(graph); } diff --git a/src/Test/ordertest.c b/src/Test/ordertest.c index 852df34..eef8c36 100644 --- a/src/Test/ordertest.c +++ b/src/Test/ordertest.c @@ -16,13 +16,8 @@ int main(int numargs, char **argv) { addConstraint(solver, b1); addConstraint(solver, b2); if (startEncoding(solver) == 1) - printf("O(5,1)=%d O(1,4)=%d O(5,4)=%d O(1,5)=%d O(1111,5)=%d\n", - getOrderConstraintValue(solver, order, 5, 1), - getOrderConstraintValue(solver, order, 1, 4), - getOrderConstraintValue(solver, order, 5, 4), - getOrderConstraintValue(solver, order, 1, 5), - getOrderConstraintValue(solver, order, 1111, 5)); + printf("SAT\n"); else printf("UNSAT\n"); deleteSolver(solver); -} \ No newline at end of file +} -- 2.34.1