From: Tim King Date: Thu, 10 Nov 2016 17:40:23 +0000 (-0800) Subject: Added PtrCloser guards for constructNodePtr. This ensures garbage collection on type... X-Git-Tag: cvc5-1.0.0~5990 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=13be3be39454a3cf7b05c4399a53bd2dd27996f6;p=cvc5.git Added PtrCloser guards for constructNodePtr. This ensures garbage collection on type checking exceptions. --- diff --git a/src/expr/node_builder.h b/src/expr/node_builder.h index 0dd4e44e8..d92524a19 100644 --- a/src/expr/node_builder.h +++ b/src/expr/node_builder.h @@ -171,6 +171,7 @@ namespace CVC4 { #include "base/cvc4_assert.h" #include "base/output.h" +#include "base/ptr_closer.h" #include "expr/kind.h" #include "expr/metakind.h" #include "expr/node_value.h" @@ -887,16 +888,18 @@ Node NodeBuilder::constructNode() const { template Node* NodeBuilder::constructNodePtr() { - Node *np = new Node(constructNV()); - maybeCheckType(*np); - return np; + // maybeCheckType() can throw an exception. Make sure to call the destructor + // on the exception branch. + PtrCloser np(new Node(constructNV())); + maybeCheckType(*np.get()); + return np.release(); } template Node* NodeBuilder::constructNodePtr() const { - Node *np = new Node(constructNV()); - maybeCheckType(*np); - return np; + PtrCloser np(new Node(constructNV())); + maybeCheckType(*np.get()); + return np.release(); } template