File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -506,10 +506,23 @@ struct Node {
506506 // ! The data bytes in this expression (only for HASH160/HASH256/SHA256/RIPEMD10).
507507 const std::vector<unsigned char > data;
508508 // ! Subexpressions (for WRAP_*/AND_*/OR_*/ANDOR/THRESH)
509- const std::vector<NodeRef<Key>> subs;
509+ mutable std::vector<NodeRef<Key>> subs;
510510 // ! The Script context for this node. Either P2WSH or Tapscript.
511511 const MiniscriptContext m_script_ctx;
512512
513+ /* Destroy the shared pointers iteratively to avoid a stack-overflow due to recursive calls
514+ * to the subs' destructors. */
515+ ~Node () {
516+ while (!subs.empty ()) {
517+ auto node = std::move (subs.back ());
518+ subs.pop_back ();
519+ while (!node->subs .empty ()) {
520+ subs.push_back (std::move (node->subs .back ()));
521+ node->subs .pop_back ();
522+ }
523+ }
524+ }
525+
513526private:
514527 // ! Cached ops counts.
515528 const internal::Ops ops;
You can’t perform that action at this time.
0 commit comments