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 {
506
506
// ! The data bytes in this expression (only for HASH160/HASH256/SHA256/RIPEMD10).
507
507
const std::vector<unsigned char > data;
508
508
// ! Subexpressions (for WRAP_*/AND_*/OR_*/ANDOR/THRESH)
509
- const std::vector<NodeRef<Key>> subs;
509
+ mutable std::vector<NodeRef<Key>> subs;
510
510
// ! The Script context for this node. Either P2WSH or Tapscript.
511
511
const MiniscriptContext m_script_ctx;
512
512
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
+
513
526
private:
514
527
// ! Cached ops counts.
515
528
const internal::Ops ops;
You can’t perform that action at this time.
0 commit comments