diff options
author | Tim King <taking@google.com> | 2016-11-10 09:40:23 -0800 |
---|---|---|
committer | Tim King <taking@google.com> | 2016-11-10 09:40:23 -0800 |
commit | 13be3be39454a3cf7b05c4399a53bd2dd27996f6 (patch) | |
tree | 9689de115cb5c4c362a2cc5f7f83b6a47aab1cb6 /src/expr | |
parent | 8142799520aa07d6134314761de9d47ac14d27b0 (diff) |
Added PtrCloser guards for constructNodePtr. This ensures garbage collection on type checking exceptions.
Diffstat (limited to 'src/expr')
-rw-r--r-- | src/expr/node_builder.h | 15 |
1 files changed, 9 insertions, 6 deletions
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<nchild_thresh>::constructNode() const { template <unsigned nchild_thresh> Node* NodeBuilder<nchild_thresh>::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<Node> np(new Node(constructNV())); + maybeCheckType(*np.get()); + return np.release(); } template <unsigned nchild_thresh> Node* NodeBuilder<nchild_thresh>::constructNodePtr() const { - Node *np = new Node(constructNV()); - maybeCheckType(*np); - return np; + PtrCloser<Node> np(new Node(constructNV())); + maybeCheckType(*np.get()); + return np.release(); } template <unsigned nchild_thresh> |